From 10e3be8c128f4b1261ea70c47451d1f57fa8d175 Mon Sep 17 00:00:00 2001 From: Jochem Klaver Date: Wed, 26 Apr 2023 16:51:30 +0200 Subject: [PATCH] Symfony 6 --- .gitattributes | 4 ++ .github/workflows/qa.yml | 2 +- CHANGELOG.md | 9 ++++ composer.json | 16 +++---- .../TranslatePageEventPropagationBuilder.php | 8 ++-- src/Command/AliasCommand.php | 15 +++--- src/Command/CheckContentItemsCommand.php | 20 ++++---- src/Command/CleanAliasCommand.php | 9 ++-- src/Command/ListCommand.php | 22 ++++----- src/Controller/AbstractController.php | 2 +- src/Controller/PageController.php | 46 ++++++------------- src/Event/PageViewEvent.php | 2 +- src/Type/ContentItemRegionType.php | 2 +- src/Type/ContentItemTypeType.php | 2 +- src/Type/DiscriminatorMapType.php | 2 +- src/ZichtPageBundle.php | 2 +- .../GenerateAdminServicesCompilerPassTest.php | 14 +++--- z2.yml | 4 -- 18 files changed, 80 insertions(+), 101 deletions(-) delete mode 100644 z2.yml diff --git a/.gitattributes b/.gitattributes index 17d5dc6..14cdaf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,7 @@ /.gitattributes export-ignore /.gitignore export-ignore /.github export-ignore +/.php-cs-fixer.dist.php export-ignore +/phpunit.xml.dist export-ignore +/psalm.xml export-ignore +/tests/ export-ignore diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 8fe95cf..84f05d0 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - php: [ '7.4', '8.1' ] + php: ['8.1', '8.3'] name: PHP ${{ matrix.php }} steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f2eb6..4053fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added|Changed|Deprecated|Removed|Fixed|Security Nothing so far +## 9.0.0 - 2024-05-02 +### Added +- Support for Symfony 6 +### Removed +- Support for PHP 7.4 +### Changed +- Made PageController final (natively instead of by annotation) +- Using attributes instead of annotations for routes + ## 8.2.1 - 2023-09-15 ### Fixed - Replaced deprecated `AnonymousToken` by `NullToken`. diff --git a/composer.json b/composer.json index 4db4a8d..1c19833 100644 --- a/composer.json +++ b/composer.json @@ -4,16 +4,16 @@ "type": "symfony-bundle", "license": "MIT", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "sonata-project/admin-bundle": "^4.21.0", - "symfony/config": "^5.4", - "symfony/console": "^5.4", - "symfony/security-core": "^5.4", + "symfony/config": "^6.4", + "symfony/console": "^6.4", + "symfony/security-core": "^6.4", "twig/twig": "^2.7 || ^3", - "zicht/admin-bundle": "^8", - "zicht/framework-extra-bundle": "^10", - "zicht/menu-bundle": "^6", - "zicht/url-bundle": "^7", + "zicht/admin-bundle": "^9", + "zicht/framework-extra-bundle": "^11", + "zicht/menu-bundle": "^7", + "zicht/url-bundle": "^8", "zicht/util": "^2" }, "require-dev": { diff --git a/src/AdminMenu/TranslatePageEventPropagationBuilder.php b/src/AdminMenu/TranslatePageEventPropagationBuilder.php index a2b76c0..b6194c5 100644 --- a/src/AdminMenu/TranslatePageEventPropagationBuilder.php +++ b/src/AdminMenu/TranslatePageEventPropagationBuilder.php @@ -52,8 +52,8 @@ public function buildAndForwardEvent(Event $e): void $this->router->generate( 'zicht_page_page_view', [ - 'id' => $page->getId(), - '_locale' => 'zz', + 'id' => $page->getId(), + '_locale' => 'zz', ] ), 'Vertalingen' @@ -66,8 +66,8 @@ public function buildAndForwardEvent(Event $e): void $this->router->generate( 'zicht_page_page_view', [ - 'id' => $page->getId(), - '_locale' => $page->getLanguage(), + 'id' => $page->getId(), + '_locale' => $page->getLanguage(), ] ), 'Pagina herladen' diff --git a/src/Command/AliasCommand.php b/src/Command/AliasCommand.php index 5fa5dc7..8fc119b 100644 --- a/src/Command/AliasCommand.php +++ b/src/Command/AliasCommand.php @@ -6,6 +6,7 @@ namespace Zicht\Bundle\PageBundle\Command; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -19,18 +20,14 @@ /** * Generates URL aliases for all pages. */ +#[AsCommand('zicht:page:alias')] class AliasCommand extends Command { - protected static $defaultName = 'zicht:page:alias'; + private ManagerRegistry $doctrine; - /** @var ManagerRegistry */ - private $doctrine; + private Aliaser $aliaser; - /** @var Aliaser */ - private $aliaser; - - /** @var PageManager */ - private $pageManager; + private PageManager $pageManager; public function __construct(ManagerRegistry $doctrine, Aliaser $aliaser, PageManager $pageManager, string $name = null) { @@ -94,6 +91,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progress->finish(); call_user_func($onDone); - return 0; + return Command::SUCCESS; } } diff --git a/src/Command/CheckContentItemsCommand.php b/src/Command/CheckContentItemsCommand.php index 9dccfc7..b2442eb 100644 --- a/src/Command/CheckContentItemsCommand.php +++ b/src/Command/CheckContentItemsCommand.php @@ -6,7 +6,9 @@ namespace Zicht\Bundle\PageBundle\Command; use Doctrine\Persistence\ManagerRegistry; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -14,21 +16,17 @@ use Symfony\Component\Console\Output\OutputInterface; use Zicht\Bundle\PageBundle\Entity\Page; +#[AsCommand('zicht:page:contentitems:check')] class CheckContentItemsCommand extends Command { - /** @var bool */ - protected $isVeryVerbose; + private ManagerRegistry $doctrine; - /** @var bool */ - protected $force; + /** @psalm-suppress PropertyNotSetInConstructor */ + protected LoggerInterface $logger; - /** @var ConsoleLogger */ - protected $logger; + protected bool $isVeryVerbose = false; - /** @var ManagerRegistry */ - private $doctrine; - - protected static $defaultName = 'zicht:page:contentitems:check'; + protected bool $force = false; public function __construct(ManagerRegistry $doctrine, string $name = null) { @@ -118,7 +116,7 @@ function ($name) use ($matrix) { } } - return 0; + return Command::SUCCESS; } /** diff --git a/src/Command/CleanAliasCommand.php b/src/Command/CleanAliasCommand.php index dfa7c96..e0ca859 100644 --- a/src/Command/CleanAliasCommand.php +++ b/src/Command/CleanAliasCommand.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Connection; use Symfony\Bridge\Doctrine\ManagerRegistry; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -17,12 +18,10 @@ /** * Remove aliases referencing pages that do not exist anymore. */ +#[AsCommand('zicht:page:clean:alias')] class CleanAliasCommand extends Command { - protected static $defaultName = 'zicht:page:clean:alias'; - - /** @var ManagerRegistry */ - private $doctrine; + private ManagerRegistry $doctrine; public function __construct(ManagerRegistry $doctrine, string $name = null) { @@ -103,6 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $connection->query(sprintf('DELETE FROM url_alias WHERE id IN (%s)', implode(', ', $aliasIds))); $output->writeln(sprintf('Removed %d aliases', count($records))); - return 0; + return Command::SUCCESS; } } diff --git a/src/Command/ListCommand.php b/src/Command/ListCommand.php index 08c530c..7e2cebd 100644 --- a/src/Command/ListCommand.php +++ b/src/Command/ListCommand.php @@ -5,31 +5,29 @@ namespace Zicht\Bundle\PageBundle\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Zicht\Bundle\PageBundle\Manager\PageManager; -use Zicht\Bundle\UrlBundle\Url\Provider; +use Zicht\Bundle\UrlBundle\Url\Provider as UrlProvider; /** * List all page urls. Useful for testing. */ +#[AsCommand('zicht:page:list')] class ListCommand extends Command { - protected static $defaultName = 'zicht:page:list'; + private PageManager $pageManager; - /** @var PageManager */ - private $pageManager; + private UrlProvider $urlProvider; - /** @var Provider */ - private $provider; - - public function __construct(PageManager $pageManager, Provider $provider, string $name = null) + public function __construct(PageManager $pageManager, UrlProvider $urlProvider, string $name = null) { parent::__construct($name); $this->pageManager = $pageManager; - $this->provider = $provider; + $this->urlProvider = $urlProvider; } protected function configure() @@ -40,14 +38,12 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output): int { $pages = $this->pageManager->getBaseRepository()->findAll(); - $urlProvider = $this->provider; - $baseUrl = rtrim($input->getOption('base-url'), '/'); foreach ($pages as $page) { - $output->writeln($baseUrl . $urlProvider->url($page)); + $output->writeln($baseUrl . $this->urlProvider->url($page)); } - return 0; + return Command::SUCCESS; } } diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index c8972c5..acace31 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -9,7 +9,7 @@ use Zicht\Bundle\PageBundle\Manager\PageManager; /** - * @deprecated extend {@see \Symfony\Bundle\FrameworkBundle\Controller\AbstractController} directly. + * @deprecated extend {@see BaseAbstractController} directly. */ abstract class AbstractController extends BaseAbstractController { diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index 9455d5a..d68dacc 100644 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -1,7 +1,4 @@ - */ namespace Zicht\Bundle\PageBundle\Controller; @@ -9,7 +6,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Zicht\Bundle\PageBundle\Manager\PageManager; use Zicht\Bundle\PageBundle\Security\PageViewValidation; use Zicht\Bundle\UrlBundle\Url\Provider as UrlProvider; @@ -17,11 +14,11 @@ /** * Controller for public page actions * - * @final in the future. You should not extend this PageController as this will result in duplication of + * Final: You should not extend this PageController as this will result in duplication of * its routes and will cause unexpected behaviour. Use the {@see PageControllerTrait} to use handy functionalities - * that were formerly available only in this PageController. + * that were previously available only in this PageController. */ -class PageController extends AbstractController +final class PageController extends AbstractController { use PageControllerTrait; @@ -51,40 +48,23 @@ public static function getSubscribedServices(): array ); } - /** - * Redirects to the page identified by the passed id. - * - * @param string $id - * @Route("page/{id}/redirect", name="page_redirect") - */ - public function redirectAction($id): RedirectResponse + /** Redirects to the page identified by the passed id. */ + #[Route('page/{id}/redirect', name: 'page_redirect')] + public function redirectAction(int $id): RedirectResponse { return new RedirectResponse($this->generateUrl('zicht_page_page_view', ['id' => $id])); } - /** - * Redirects to the specified page. This is useful for posting an autocomplete ID, which in turn redirects to - * the specified page. - * - * @Route("/goto") - */ - public function gotoAction(Request $r): RedirectResponse + /** Redirects to the specified page. This is useful for posting an autocomplete ID, which in turn redirects to the specified page. */ + #[Route('/goto')] + public function gotoAction(Request $request): RedirectResponse { - return $this->redirect( - $this->urlProvider->url($this->getPageManager()->findForView($r->get('id'))) - ); + return $this->redirect($this->urlProvider->url($this->getPageManager()->findForView($request->get('id')))); } - /** - * @param string $id - * @Route("page/{id}") - */ - public function viewAction(Request $request, $id): Response + #[Route('page/{id}')] + public function viewAction(Request $request, int $id): Response { - if (get_class($this) !== __CLASS__) { - trigger_deprecation('zicht/page-bundle', '8.2', 'Extending the "%s" controller is deprecated as it will be final in the future. Implement your own "viewAction()" and/or use "%s" functionalities.', __CLASS__, PageControllerTrait::class); - } - $page = $this->pageManager->findForView($id); $this->isViewActionAllowed($page); diff --git a/src/Event/PageViewEvent.php b/src/Event/PageViewEvent.php index 35bcdbc..7a91c5b 100644 --- a/src/Event/PageViewEvent.php +++ b/src/Event/PageViewEvent.php @@ -27,7 +27,7 @@ public function __construct(PageInterface $page) /** * Return the page attached to this event * - * @return \Zicht\Bundle\PageBundle\Model\PageInterface + * @return PageInterface */ public function getPage() { diff --git a/src/Type/ContentItemRegionType.php b/src/Type/ContentItemRegionType.php index 3e77756..57f35a5 100644 --- a/src/Type/ContentItemRegionType.php +++ b/src/Type/ContentItemRegionType.php @@ -102,7 +102,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) $view->vars['matrix'] = json_encode($matrix); } - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'zicht_content_item_region'; } diff --git a/src/Type/ContentItemTypeType.php b/src/Type/ContentItemTypeType.php index 2e45a8c..f9a09ad 100644 --- a/src/Type/ContentItemTypeType.php +++ b/src/Type/ContentItemTypeType.php @@ -135,7 +135,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) } } - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'zicht_content_item_type'; } diff --git a/src/Type/DiscriminatorMapType.php b/src/Type/DiscriminatorMapType.php index 46895b4..97764ac 100755 --- a/src/Type/DiscriminatorMapType.php +++ b/src/Type/DiscriminatorMapType.php @@ -60,7 +60,7 @@ public function getParent() return ChoiceType::class; } - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'zicht_discriminator_map'; } diff --git a/src/ZichtPageBundle.php b/src/ZichtPageBundle.php index 5bec81d..9a476e6 100644 --- a/src/ZichtPageBundle.php +++ b/src/ZichtPageBundle.php @@ -14,7 +14,7 @@ */ class ZichtPageBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/tests/DependencyInjection/CompilerPass/GenerateAdminServicesCompilerPassTest.php b/tests/DependencyInjection/CompilerPass/GenerateAdminServicesCompilerPassTest.php index a84f92d..55cbebe 100644 --- a/tests/DependencyInjection/CompilerPass/GenerateAdminServicesCompilerPassTest.php +++ b/tests/DependencyInjection/CompilerPass/GenerateAdminServicesCompilerPassTest.php @@ -42,7 +42,7 @@ public function testBareConfig() public function testValidConfig() { - $c = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + $c = new ContainerBuilder(); $defs = [ 'zicht_page.page_manager' => new \Symfony\Component\DependencyInjection\Definition(), @@ -64,15 +64,15 @@ public function testValidConfig() $c->setParameter( 'zicht_page.config', [ - 'admin' => [ - 'base' => [ - 'page' => 'page.admin', - 'contentItem' => 'ci.admin', + 'admin' => [ + 'base' => [ + 'page' => 'page.admin', + 'contentItem' => 'ci.admin', + ], ], - ], ] ); - $pass = new \Zicht\Bundle\PageBundle\DependencyInjection\CompilerPass\GenerateAdminServicesCompilerPass(); + $pass = new GenerateAdminServicesCompilerPass(); $pass->process($c); $this->expectNotToPerformAssertions(); } diff --git a/z2.yml b/z2.yml deleted file mode 100644 index 3ab7ec9..0000000 --- a/z2.yml +++ /dev/null @@ -1,4 +0,0 @@ -plugins: ['core', 'svn'] - -vcs: - url: svn://zon/projecten/zicht-libraries/ZichtPageBundle