Skip to content

Commit

Permalink
Merge branch release/v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Dec 6, 2024
1 parent 5cab3c9 commit f2a15d8
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 312 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,7 +35,5 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
3 changes: 0 additions & 3 deletions Makefile

This file was deleted.

32 changes: 15 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"doctrine/annotations": "^1.0",
"php": ">=8.2",
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.8.1",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "~2.19.0",
"doctrine/orm": "~2.20.0",
"jms/serializer": "^3.9.0",
"league/flysystem": "^3.0",
"roadiz/models": "2.3.*",
"roadiz/rozier": "2.3.*",
"sensio/framework-extra-bundle": "^6.1",
"roadiz/models": "2.4.*",
"roadiz/rozier": "2.4.*",
"symfony/asset": "6.4.*",
"symfony/cache": "6.4.*",
"symfony/dotenv": "6.4.*",
Expand All @@ -44,25 +43,24 @@
"symfony/twig-bundle": "6.4.*",
"symfony/validator": "6.4.*",
"symfony/yaml": "6.4.*",
"twig/extra-bundle": "^3.0",
"twig/extra-bundle": "^3.16",
"twig/intl-extra": "*",
"twig/string-extra": "*",
"twig/twig": "^3.1"
"twig/twig": "^3.16"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan": "^1.5.3",
"phpstan/phpstan-doctrine": "^1.3",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5",
"roadiz/compat-bundle": "2.4.*",
"roadiz/core-bundle": "2.4.*",
"roadiz/documents": "2.4.*",
"roadiz/entity-generator": "2.4.*",
"roadiz/rozier-bundle": "2.4.*",
"symfony/browser-kit": "6.4.*",
"symfony/phpunit-bridge": "^7.0",
"symfony/stopwatch": "6.4.*",
"roadiz/core-bundle": "2.3.*",
"roadiz/compat-bundle": "2.3.*",
"roadiz/rozier-bundle": "2.3.*",
"roadiz/documents": "2.3.*",
"roadiz/entity-generator": "2.3.*"
"symfony/stopwatch": "6.4.*"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -89,8 +87,8 @@
},
"extra": {
"branch-alias": {
"dev-main": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-main": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
}
}
}
13 changes: 0 additions & 13 deletions phpcs.xml.dist

This file was deleted.

68 changes: 13 additions & 55 deletions src/Controller/Admin/FontsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,126 +22,84 @@

class FontsController extends AbstractAdminController
{
private FilesystemOperator $fontStorage;

public function __construct(
FilesystemOperator $fontStorage,
private readonly FilesystemOperator $fontStorage,
SerializerInterface $serializer,
UrlGeneratorInterface $urlGenerator
UrlGeneratorInterface $urlGenerator,
) {
parent::__construct($serializer, $urlGenerator);
$this->fontStorage = $fontStorage;
}

/**
* @inheritDoc
*/
protected function supports(PersistableInterface $item): bool
{
return $item instanceof Font;
}

/**
* @inheritDoc
*/
protected function getNamespace(): string
{
return 'font';
}

/**
* @inheritDoc
*/
protected function createEmptyItem(Request $request): PersistableInterface
{
return new Font();
}

/**
* @inheritDoc
*/
protected function getTemplateFolder(): string
{
return '@RoadizFont/admin';
}

/**
* @inheritDoc
*/
protected function getRequiredRole(): string
{
return 'ROLE_ACCESS_FONTS';
}

/**
* @inheritDoc
*/
protected function getEntityClass(): string
{
return Font::class;
}

/**
* @inheritDoc
*/
protected function getFormType(): string
{
return FontType::class;
}

/**
* @inheritDoc
*/
protected function getDefaultOrder(Request $request): array
{
return ['name' => 'ASC'];
}

/**
* @inheritDoc
*/
protected function getDefaultRouteName(): string
{
return 'fontsHomePage';
}

/**
* @inheritDoc
*/
protected function getEditRouteName(): string
{
return 'fontsEditPage';
}

/**
* @inheritDoc
*/
protected function createUpdateEvent(PersistableInterface $item): ?Event
{
if ($item instanceof Font) {
return new PreUpdatedFontEvent($item);
}

return null;
}

/**
* @inheritDoc
*/
protected function getEntityName(PersistableInterface $item): string
{
if ($item instanceof Font) {
return $item->getName();
}
throw new \InvalidArgumentException('Item should be instance of ' . $this->getEntityClass());
throw new \InvalidArgumentException('Item should be instance of '.$this->getEntityClass());
}

/**
* Return a ZipArchive of requested font.
*
* @param Request $request
* @param int $id
*
* @return BinaryFileResponse
* @throws FilesystemException
*/
public function downloadAction(Request $request, int $id): BinaryFileResponse
Expand All @@ -151,37 +109,37 @@ public function downloadAction(Request $request, int $id): BinaryFileResponse
/** @var Font|null $font */
$font = $this->em()->find(Font::class, $id);

if ($font !== null) {
if (null !== $font) {
// Prepare File
$file = tempnam(sys_get_temp_dir(), "font_" . $font->getId());
$file = tempnam(sys_get_temp_dir(), 'font_'.$font->getId());
if (false === $file) {
throw new \RuntimeException('Cannot create temporary file.');
}
$zip = new \ZipArchive();
$zip->open($file, \ZipArchive::CREATE);

if ("" != $font->getEOTFilename()) {
if ('' != $font->getEOTFilename()) {
$zip->addFromString($font->getEOTFilename(), $this->fontStorage->read($font->getEOTRelativeUrl()));
}
if ("" != $font->getSVGFilename()) {
if ('' != $font->getSVGFilename()) {
$zip->addFromString($font->getSVGFilename(), $this->fontStorage->read($font->getSVGRelativeUrl()));
}
if ("" != $font->getWOFFFilename()) {
if ('' != $font->getWOFFFilename()) {
$zip->addFromString($font->getWOFFFilename(), $this->fontStorage->read($font->getWOFFRelativeUrl()));
}
if ("" != $font->getWOFF2Filename()) {
if ('' != $font->getWOFF2Filename()) {
$zip->addFromString($font->getWOFF2Filename(), $this->fontStorage->read($font->getWOFF2RelativeUrl()));
}
if ("" != $font->getOTFFilename()) {
if ('' != $font->getOTFFilename()) {
$zip->addFromString($font->getOTFFilename(), $this->fontStorage->read($font->getOTFRelativeUrl()));
}
// Close and send to users
$zip->close();
$filename = StringHandler::slugify($font->getName() . ' ' . $font->getReadableVariant()) . '.zip';
$filename = StringHandler::slugify($font->getName().' '.$font->getReadableVariant()).'.zip';

return (new BinaryFileResponse($file, Response::HTTP_OK, [
'content-type' => 'application/zip',
'content-disposition' => 'attachment; filename=' . $filename,
'content-disposition' => 'attachment; filename='.$filename,
], false))->deleteFileAfterSend(true);
}

Expand Down
33 changes: 12 additions & 21 deletions src/Controller/FontFaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

final class FontFaceController
final readonly class FontFaceController
{
public function __construct(
private readonly FilesystemOperator $fontStorage,
private readonly ManagerRegistry $managerRegistry,
private readonly Environment $templating,
private FilesystemOperator $fontStorage,
private ManagerRegistry $managerRegistry,
private Environment $templating,
) {
}

Expand All @@ -28,27 +28,27 @@ private function getFontData(Font $font, string $extension): ?array
return match ($extension) {
'eot' => [
$this->fontStorage->read($font->getEOTRelativeUrl()),
Font::MIME_EOT
Font::MIME_EOT,
],
'woff' => [
$this->fontStorage->read($font->getWOFFRelativeUrl()),
Font::MIME_WOFF
Font::MIME_WOFF,
],
'woff2' => [
$this->fontStorage->read($font->getWOFF2RelativeUrl()),
Font::MIME_WOFF2
Font::MIME_WOFF2,
],
'svg' => [
$this->fontStorage->read($font->getSVGRelativeUrl()),
Font::MIME_SVG
Font::MIME_SVG,
],
'otf' => [
$this->fontStorage->read($font->getOTFRelativeUrl()),
Font::MIME_OTF
Font::MIME_OTF,
],
'ttf' => [
$this->fontStorage->read($font->getOTFRelativeUrl()),
Font::MIME_TTF
Font::MIME_TTF,
],
default => null,
};
Expand All @@ -60,12 +60,6 @@ private function getFontData(Font $font, string $extension): ?array
/**
* Request a single protected font file from Roadiz.
*
* @param Request $request
* @param string $filename
* @param int $variant
* @param string $extension
*
* @return Response
* @throws \Exception
*/
public function fontFileAction(Request $request, string $filename, int $variant, string $extension): Response
Expand Down Expand Up @@ -103,7 +97,7 @@ public function fontFileAction(Request $request, string $filename, int $variant,
return $response;
}
}
$msg = "Font doesn't exist " . $filename;
$msg = "Font doesn't exist ".$filename;

return new Response(
$msg,
Expand All @@ -115,9 +109,6 @@ public function fontFileAction(Request $request, string $filename, int $variant,
/**
* Request the font-face CSS file listing available fonts.
*
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function fontFacesAction(Request $request): Response
Expand Down Expand Up @@ -151,7 +142,7 @@ public function fontFacesAction(Request $request): Response
];
/** @var Font $font */
foreach ($fonts as $font) {
$variantHash = $font->getHash() . $font->getVariant();
$variantHash = $font->getHash().$font->getVariant();
$assignation['fonts'][] = [
'font' => $font,
'variantHash' => $variantHash,
Expand Down
Loading

0 comments on commit f2a15d8

Please sign in to comment.