diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 189e3a5..3b17d56 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.0', '8.1'] steps: - uses: shivammathur/setup-php@v2 with: diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..316f0e9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: php +php: + - '8.0' + - '8.1' + - 'nightly' +jobs: + allow_failures: + - php: 'nightly' +install: + - composer install --dev --no-scripts --no-suggest + +script: + - vendor/bin/phpcs -p ./src + - vendor/bin/phpstan analyse -c phpstan.neon diff --git a/LICENSE.md b/LICENSE.md index 8e18fa6..d4d8a00 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright © 2024 Ambroise Maupate +Copyright © 2023 Ambroise Maupate Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 3db82db..1be8d1b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # Roadiz Font bundle -**Manage and expose web fonts with Roadiz CMS** ![Run test status](https://github.com/roadiz/font-bundle/actions/workflows/run-test.yml/badge.svg?branch=develop) diff --git a/composer.json b/composer.json index 8aba042..5845cb5 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,9 @@ { "name": "roadiz/font-bundle", - "description": "Manage and expose web fonts with Roadiz CMS", "license": "MIT", "keywords": [ "cms", "backoffice", - "roadiz", "rezo zero" ], "authors": [ @@ -17,34 +15,32 @@ } ], "type": "symfony-bundle", - "minimum-stability": "dev", - "prefer-stable": true, "require": { - "php": ">=8.1", + "php": ">=8.0", "doctrine/annotations": "^1.0", "doctrine/doctrine-bundle": "^2.8.1", "doctrine/doctrine-migrations-bundle": "^3.1", - "doctrine/orm": "~2.19.0", + "doctrine/orm": "<2.17", "jms/serializer": "^3.9.0", "league/flysystem": "^3.0", - "roadiz/models": "2.3.*", - "roadiz/rozier": "2.3.*", + "roadiz/models": "2.1.*", + "roadiz/rozier": "2.1.*", "sensio/framework-extra-bundle": "^6.1", - "symfony/asset": "6.4.*", - "symfony/cache": "6.4.*", - "symfony/dotenv": "6.4.*", - "symfony/expression-language": "6.4.*", - "symfony/form": "6.4.*", - "symfony/framework-bundle": "6.4.*", - "symfony/http-client": "6.4.*", - "symfony/intl": "6.4.*", - "symfony/runtime": "6.4.*", - "symfony/string": "6.4.*", - "symfony/translation": "6.4.*", - "symfony/twig-bundle": "6.4.*", - "symfony/validator": "6.4.*", - "symfony/yaml": "6.4.*", - "twig/extra-bundle": "^3.0", + "symfony/asset": "5.4.*", + "symfony/cache": "5.4.*", + "symfony/dotenv": "5.4.*", + "symfony/expression-language": "5.4.*", + "symfony/form": "5.4.*", + "symfony/framework-bundle": "5.4.*", + "symfony/http-client": "5.4.*", + "symfony/intl": "5.4.*", + "symfony/runtime": "5.4.*", + "symfony/string": "5.4.*", + "symfony/translation": "5.4.*", + "symfony/twig-bundle": "5.4.*", + "symfony/validator": "5.4.*", + "symfony/yaml": "5.4.*", + "twig/extra-bundle": "^2.12|^3.0", "twig/intl-extra": "*", "twig/string-extra": "*", "twig/twig": "^3.1" @@ -55,14 +51,14 @@ "phpstan/phpstan-doctrine": "^1.3", "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.5", - "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/browser-kit": "5.4.*", + "symfony/phpunit-bridge": "5.4.*", + "symfony/stopwatch": "5.4.*", + "roadiz/core-bundle": "2.1.*", + "roadiz/compat-bundle": "2.1.*", + "roadiz/rozier-bundle": "2.1.*", + "roadiz/documents": "2.1.*", + "roadiz/entity-generator": "2.1.*" }, "config": { "optimize-autoloader": true, @@ -89,8 +85,8 @@ }, "extra": { "branch-alias": { - "dev-main": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-main": "2.1.x-dev", + "dev-develop": "2.2.x-dev" } } } diff --git a/migrations/Version20230607134442.php b/migrations/Version20230607134442.php deleted file mode 100644 index d184e45..0000000 --- a/migrations/Version20230607134442.php +++ /dev/null @@ -1,36 +0,0 @@ -addSql('ALTER TABLE fonts CHANGE eot_filename eot_filename VARCHAR(100) DEFAULT NULL, CHANGE woff_filename woff_filename VARCHAR(100) DEFAULT NULL, CHANGE woff2_filename woff2_filename VARCHAR(100) DEFAULT NULL, CHANGE otf_filename otf_filename VARCHAR(100) DEFAULT NULL, CHANGE svg_filename svg_filename VARCHAR(100) DEFAULT NULL, CHANGE name name VARCHAR(100) NOT NULL, CHANGE hash hash VARCHAR(128) NOT NULL, CHANGE folder folder VARCHAR(100) NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE fonts CHANGE eot_filename eot_filename VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE woff_filename woff_filename VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE woff2_filename woff2_filename VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE otf_filename otf_filename VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE svg_filename svg_filename VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE name name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE hash hash VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE folder folder VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/migrations/Version20230828092912.php b/migrations/Version20230828092912.php deleted file mode 100644 index 21372ca..0000000 --- a/migrations/Version20230828092912.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('CREATE INDEX font_created_at ON fonts (created_at)'); - $this->addSql('CREATE INDEX font_updated_at ON fonts (updated_at)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX font_created_at ON fonts'); - $this->addSql('DROP INDEX font_updated_at ON fonts'); - } -} diff --git a/phpstan.neon b/phpstan.neon index 0226785..b42b403 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 5 paths: - src excludePaths: @@ -7,8 +7,6 @@ parameters: - */bower_components/* - */static/* ignoreErrors: - - identifier: missingType.iterableValue - - identifier: missingType.generics - '#Call to an undefined method RZ\\Roadiz\\CoreBundle\\Repository#' - '#Call to an undefined method RZ\\Roadiz\\UserBundle\\Repository#' - '#Call to an undefined method Doctrine\\Persistence\\ObjectRepository#' @@ -28,9 +26,9 @@ parameters: - '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#' - '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#' - '#should return Doctrine\\Common\\Collections\\Collection]+Interface> but returns Doctrine\\Common\\Collections\\Collection]+>#' - - '#but returns Doctrine\\Common\\Collections\\ReadableCollection]+>#' - - '#does not accept Doctrine\\Common\\Collections\\ReadableCollection]+>#' reportUnmatchedIgnoredErrors: false + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false includes: - vendor/phpstan/phpstan-doctrine/extension.neon diff --git a/src/Controller/Admin/FontsController.php b/src/Controller/Admin/FontsController.php index 894ea81..65b99ac 100644 --- a/src/Controller/Admin/FontsController.php +++ b/src/Controller/Admin/FontsController.php @@ -154,9 +154,6 @@ public function downloadAction(Request $request, int $id): BinaryFileResponse if ($font !== null) { // Prepare File $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); diff --git a/src/Controller/FontFaceController.php b/src/Controller/FontFaceController.php index 54805b5..502811b 100644 --- a/src/Controller/FontFaceController.php +++ b/src/Controller/FontFaceController.php @@ -15,11 +15,18 @@ final class FontFaceController { + private ManagerRegistry $managerRegistry; + private Environment $templating; + private FilesystemOperator $fontStorage; + public function __construct( - private readonly FilesystemOperator $fontStorage, - private readonly ManagerRegistry $managerRegistry, - private readonly Environment $templating, + FilesystemOperator $fontStorage, + ManagerRegistry $managerRegistry, + Environment $templating, ) { + $this->managerRegistry = $managerRegistry; + $this->templating = $templating; + $this->fontStorage = $fontStorage; } private function getFontData(Font $font, string $extension): ?array @@ -79,7 +86,7 @@ public function fontFileAction(Request $request, string $filename, int $variant, if (null !== $font) { [$fontData, $mime] = $this->getFontData($font, $extension); - if (\is_string($fontData)) { + if (null !== $fontData) { $response = new Response( '', Response::HTTP_NOT_MODIFIED, @@ -97,7 +104,7 @@ public function fontFileAction(Request $request, string $filename, int $variant, if (!$response->isNotModified($request)) { $response->setContent($fontData); $response->setStatusCode(Response::HTTP_OK); - $response->setEtag(md5($fontData)); + $response->setEtag(md5($response->getContent())); } return $response; @@ -157,12 +164,13 @@ public function fontFacesAction(Request $request): Response 'variantHash' => $variantHash, ]; } - $content = $this->templating->render( - '@RoadizFont/fonts/fontfamily.css.twig', - $assignation + $response->setContent( + $this->templating->render( + '@RoadizFont/fonts/fontfamily.css.twig', + $assignation + ) ); - $response->setContent($content); - $response->setEtag(md5($content)); + $response->setEtag(md5($response->getContent())); $response->setStatusCode(Response::HTTP_OK); return $response; diff --git a/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php b/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php index 465b2ed..19b9988 100644 --- a/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php +++ b/src/Doctrine/EventSubscriber/FontLifeCycleSubscriber.php @@ -19,11 +19,13 @@ final class FontLifeCycleSubscriber implements EventSubscriber { private static array $formats = ['svg', 'otf', 'eot', 'woff', 'woff2']; + private LoggerInterface $logger; + private FilesystemOperator $fontStorage; - public function __construct( - private readonly FilesystemOperator $fontStorage, - private readonly LoggerInterface $logger - ) { + public function __construct(FilesystemOperator $fontStorage, LoggerInterface $logger) + { + $this->logger = $logger; + $this->fontStorage = $fontStorage; } /** diff --git a/src/Entity/Font.php b/src/Entity/Font.php index 39cc3de..7cb4809 100644 --- a/src/Entity/Font.php +++ b/src/Entity/Font.php @@ -20,8 +20,6 @@ ORM\Entity(repositoryClass: FontRepository::class), ORM\Table(name: "fonts"), ORM\UniqueConstraint(columns: ["name", "variant"]), - ORM\Index(columns: ["created_at"], name: "font_created_at"), - ORM\Index(columns: ["updated_at"], name: "font_updated_at"), UniqueEntity(fields: ["name", "variant"]) ] class Font extends AbstractDateTimed @@ -88,38 +86,31 @@ class Font extends AbstractDateTimed protected ?UploadedFile $otfFile = null; protected ?UploadedFile $svgFile = null; - #[ORM\Column(name: 'eot_filename', type: 'string', length: 100, nullable: true)] - #[Assert\Length(max: 100)] + #[ORM\Column(name: 'eot_filename', type: 'string', nullable: true)] private ?string $eotFilename = null; - #[ORM\Column(name: 'woff_filename', type: 'string', length: 100, nullable: true)] - #[Assert\Length(max: 100)] + #[ORM\Column(name: 'woff_filename', type: 'string', nullable: true)] private ?string $woffFilename = null; - #[ORM\Column(name: 'woff2_filename', type: 'string', length: 100, nullable: true)] - #[Assert\Length(max: 100)] + #[ORM\Column(name: 'woff2_filename', type: 'string', nullable: true)] private ?string $woff2Filename = null; - #[ORM\Column(name: 'otf_filename', type: 'string', length: 100, nullable: true)] - #[Assert\Length(max: 100)] + #[ORM\Column(name: 'otf_filename', type: 'string', nullable: true)] private ?string $otfFilename = null; - #[ORM\Column(name: 'svg_filename', type: 'string', length: 100, nullable: true)] - #[Assert\Length(max: 100)] + #[ORM\Column(name: 'svg_filename', type: 'string', nullable: true)] private ?string $svgFilename = null; - #[ORM\Column(type: 'string', length: 100, unique: false, nullable: false)] + #[ORM\Column(type: 'string', unique: false, nullable: false)] #[Assert\NotNull] #[Assert\NotBlank] #[Assert\Length(max: 100)] private string $name = ''; - #[ORM\Column(type: 'string', length: 128, unique: false, nullable: false)] - #[Assert\Length(max: 128)] + #[ORM\Column(type: 'string', unique: false, nullable: false)] private string $hash = ''; - #[ORM\Column(type: 'string', length: 100, nullable: false)] - #[Assert\Length(max: 100)] + #[ORM\Column(type: 'string', nullable: false)] private string $folder = ''; #[ORM\Column(type: 'text', nullable: true)] diff --git a/src/EventSubscriber/UpdateFontSubscriber.php b/src/EventSubscriber/UpdateFontSubscriber.php index dcda650..64d6a28 100644 --- a/src/EventSubscriber/UpdateFontSubscriber.php +++ b/src/EventSubscriber/UpdateFontSubscriber.php @@ -16,8 +16,11 @@ */ final class UpdateFontSubscriber implements EventSubscriberInterface { - public function __construct(private readonly FontLifeCycleSubscriber $fontSubscriber) + private FontLifeCycleSubscriber $fontSubscriber; + + public function __construct(FontLifeCycleSubscriber $fontSubscriber) { + $this->fontSubscriber = $fontSubscriber; } /** diff --git a/src/Repository/FontRepository.php b/src/Repository/FontRepository.php index de702bf..c1a08ec 100644 --- a/src/Repository/FontRepository.php +++ b/src/Repository/FontRepository.php @@ -31,8 +31,7 @@ public function getLatestUpdateDate(): ?\DateTimeInterface { $query = $this->_em->createQuery(' SELECT MAX(f.updatedAt) FROM RZ\Roadiz\FontBundle\Entity\Font f'); - $updatedAt = $query->getSingleScalarResult(); - return \is_string($updatedAt) ? new \DateTimeImmutable($updatedAt) : null; + return new \DateTimeImmutable($query->getSingleScalarResult()); } } diff --git a/templates/admin/add.html.twig b/templates/admin/add.html.twig index d69ae99..e660283 100644 --- a/templates/admin/add.html.twig +++ b/templates/admin/add.html.twig @@ -22,7 +22,7 @@
{% apply spaceless %}