From c7956dc350563d97d75aa3d2b2ebf131688fea0a Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Tue, 26 Nov 2024 13:05:10 +0100 Subject: [PATCH 1/5] Fix route loading in Contao 4.13 --- composer.json | 2 +- src/ContaoManager/Plugin.php | 5 +++-- src/Controller/DownloadBulkyItemController.php | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a5cd592..ce3e85b 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": "^8.1", "composer-plugin-api": "^2.0", "codefog/contao-haste": "^5.2", - "contao/core-bundle": "^4.13.50 || ^5.3.14 || ^5.4.4", + "contao/core-bundle": "^4.13.50 || ~5.3.14 || ^5.4.4", "doctrine/dbal": "^3.4", "doctrine/orm": "^2.19", "knplabs/knp-menu": "^3.1", diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 64257a6..4fbfb10 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -11,6 +11,7 @@ use Contao\ManagerPlugin\Routing\RoutingPluginInterface; use Symfony\Component\Config\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Terminal42\NotificationCenterBundle\Controller\DownloadBulkyItemController; use Terminal42\NotificationCenterBundle\Terminal42NotificationCenterBundle; class Plugin implements BundlePluginInterface, RoutingPluginInterface @@ -27,8 +28,8 @@ public function getBundles(ParserInterface $parser): array public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) { return $resolver - ->resolve(__DIR__.'/../Controller/DownloadBulkyItemController.php', 'attribute') - ->load(__DIR__.'/../Controller/DownloadBulkyItemController.php') + ->resolve(DownloadBulkyItemController::class) + ->load(DownloadBulkyItemController::class) ; } } diff --git a/src/Controller/DownloadBulkyItemController.php b/src/Controller/DownloadBulkyItemController.php index d038ef0..06a9cb8 100644 --- a/src/Controller/DownloadBulkyItemController.php +++ b/src/Controller/DownloadBulkyItemController.php @@ -9,10 +9,12 @@ use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\UriSigner; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\Annotation\Route; use Terminal42\NotificationCenterBundle\BulkyItem\BulkyItemStorage; -#[Route('/notifications/download/{voucher}', 'nc_bulky_item_download', requirements: ['voucher' => BulkyItemStorage::VOUCHER_REGEX])] +/** + * @Route("/notifications/download/{voucher}", name="nc_bulky_item_download", requirements={"voucher"=BulkyItemStorage::VOUCHER_REGEX}) + */ class DownloadBulkyItemController { public function __construct( From 7b2595f136f7b9b763495019a40b949fc73019c2 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Tue, 26 Nov 2024 13:42:58 +0100 Subject: [PATCH 2/5] Fix the CI build --- rector.php | 23 +++++++++++++++++++ .../DownloadBulkyItemController.php | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..574ceef --- /dev/null +++ b/rector.php @@ -0,0 +1,23 @@ +skip([ + AnnotationToAttributeRector::class + ]); +}; diff --git a/src/Controller/DownloadBulkyItemController.php b/src/Controller/DownloadBulkyItemController.php index 06a9cb8..e08ea28 100644 --- a/src/Controller/DownloadBulkyItemController.php +++ b/src/Controller/DownloadBulkyItemController.php @@ -13,6 +13,8 @@ use Terminal42\NotificationCenterBundle\BulkyItem\BulkyItemStorage; /** + * Do not use PHP attribute for compatibility with Contao 4.13/Symfony 5.4. + * * @Route("/notifications/download/{voucher}", name="nc_bulky_item_download", requirements={"voucher"=BulkyItemStorage::VOUCHER_REGEX}) */ class DownloadBulkyItemController From 80b942db11fe93749a778fbcebcf80adcabfbb50 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Tue, 26 Nov 2024 15:36:34 +0100 Subject: [PATCH 3/5] Use config file instead of attribute or annotation --- config/routes.php | 12 ++++++++++++ src/ContaoManager/Plugin.php | 4 ++-- src/Controller/DownloadBulkyItemController.php | 6 ------ 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 config/routes.php diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000..cecf3d8 --- /dev/null +++ b/config/routes.php @@ -0,0 +1,12 @@ +add('nc_bulky_item_download', '/notifications/download/{voucher}') + ->controller(DownloadBulkyItemController::class) + ->requirements(['voucher' => BulkyItemStorage::VOUCHER_REGEX]) + ; +}; diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 4fbfb10..14820a9 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -28,8 +28,8 @@ public function getBundles(ParserInterface $parser): array public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) { return $resolver - ->resolve(DownloadBulkyItemController::class) - ->load(DownloadBulkyItemController::class) + ->resolve(__DIR__.'/../../config/routes.php') + ->load(__DIR__.'/../../config/routes.php') ; } } diff --git a/src/Controller/DownloadBulkyItemController.php b/src/Controller/DownloadBulkyItemController.php index e08ea28..3ec2f55 100644 --- a/src/Controller/DownloadBulkyItemController.php +++ b/src/Controller/DownloadBulkyItemController.php @@ -9,14 +9,8 @@ use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\UriSigner; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Annotation\Route; use Terminal42\NotificationCenterBundle\BulkyItem\BulkyItemStorage; -/** - * Do not use PHP attribute for compatibility with Contao 4.13/Symfony 5.4. - * - * @Route("/notifications/download/{voucher}", name="nc_bulky_item_download", requirements={"voucher"=BulkyItemStorage::VOUCHER_REGEX}) - */ class DownloadBulkyItemController { public function __construct( From e841766015fe49dd83018dad1549fa3deeeb8317 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Tue, 26 Nov 2024 16:30:26 +0100 Subject: [PATCH 4/5] Delete rector.php --- rector.php | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 rector.php diff --git a/rector.php b/rector.php deleted file mode 100644 index 574ceef..0000000 --- a/rector.php +++ /dev/null @@ -1,23 +0,0 @@ -skip([ - AnnotationToAttributeRector::class - ]); -}; From 4f2f052013615575bc3d3d7ef61bd101709cf383 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Tue, 26 Nov 2024 16:32:26 +0100 Subject: [PATCH 5/5] CS --- config/routes.php | 4 +++- src/ContaoManager/Plugin.php | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/routes.php b/config/routes.php index cecf3d8..7a5e805 100644 --- a/config/routes.php +++ b/config/routes.php @@ -1,10 +1,12 @@ add('nc_bulky_item_download', '/notifications/download/{voucher}') ->controller(DownloadBulkyItemController::class) ->requirements(['voucher' => BulkyItemStorage::VOUCHER_REGEX]) diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 14820a9..b05fc5e 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -11,7 +11,6 @@ use Contao\ManagerPlugin\Routing\RoutingPluginInterface; use Symfony\Component\Config\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\KernelInterface; -use Terminal42\NotificationCenterBundle\Controller\DownloadBulkyItemController; use Terminal42\NotificationCenterBundle\Terminal42NotificationCenterBundle; class Plugin implements BundlePluginInterface, RoutingPluginInterface