From 2dfb974cda2ad648dc9acaf47db4509886b7eaf9 Mon Sep 17 00:00:00 2001 From: Jochem Klaver Date: Wed, 26 Apr 2023 16:51:30 +0200 Subject: [PATCH] Symfony 6 --- CHANGELOG.md | 7 ++++ composer.json | 16 ++++----- src/Command/AliasCommand.php | 15 ++++---- src/Command/CheckContentItemsCommand.php | 20 +++++------ src/Command/CleanAliasCommand.php | 9 +++-- src/Command/ListCommand.php | 22 +++++------- src/Controller/PageController.php | 46 +++++++----------------- src/Type/ContentItemRegionType.php | 2 +- src/Type/ContentItemTypeType.php | 2 +- src/Type/DiscriminatorMapType.php | 2 +- 10 files changed, 59 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f2eb6..3341f99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### 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 ### Added|Changed|Deprecated|Removed|Fixed|Security Nothing so far diff --git a/composer.json b/composer.json index 4db4a8d..7458c4e 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": "^5.4 || ^6", + "symfony/console": "^5.4 || ^6", + "symfony/security-core": "^5.4 || ^6", "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": "^8 || dev-feature-symfony-6 as 9.0.0", + "zicht/framework-extra-bundle": "^10 || dev-feature-symfony-6 as 11.0.0", + "zicht/menu-bundle": "^6 || dev-feature-symfony-6 as 7.0.0", + "zicht/url-bundle": "^7 || dev-feature-symfony-6 as 8.0.0", "zicht/util": "^2" }, "require-dev": { 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/PageController.php b/src/Controller/PageController.php index 9455d5a..e95e8d6 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', name: 'page_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}', name: 'page_view')] + 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/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'; }