Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-introduce Route attribute #384

Closed
wants to merge 3 commits into from
Closed

Conversation

fritzmg
Copy link
Collaborator

@fritzmg fritzmg commented Nov 28, 2024

This re-introduces the #[Route] attribute in a way that is compatible with Symfony 5, 6 & 7 (Contao 4.13, 5.3 and 5.4+), as suggested by @Tastaturberuf.

Contao 4.13:

$ vendor/bin/contao-console debug:router nc_bulky_item_download
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Property     | Value                                                                                                                 |
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Route Name   | nc_bulky_item_download                                                                                                |
| Path         | /notifications/download/{voucher}                                                                                     |
| Path Regex   | {^/notifications/download/(?P<voucher>\d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12})$}sDu |
| Host         | ANY                                                                                                                   |
| Host Regex   |                                                                                                                       |
| Scheme       | ANY                                                                                                                   |
| Method       | ANY                                                                                                                   |
| Requirements | voucher: \d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}                                    |
| Class        | Symfony\Component\Routing\Route                                                                                       |
| Defaults     | _controller: Terminal42\NotificationCenterBundle\Controller\DownloadBulkyItemController()                             |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                                                               |
|              | utf8: true                                                                                                            |
+--------------+-----------------------------------------------------------------------------------------------------------------------+

Contao 5.3:

$ bin/console debug:router nc_bulky_item_download
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Property     | Value                                                                                                                 |
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Route Name   | nc_bulky_item_download                                                                                                |
| Path         | /notifications/download/{voucher}                                                                                     |
| Path Regex   | {^/notifications/download/(?P<voucher>\d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12})$}sDu |
| Host         | ANY                                                                                                                   |
| Host Regex   |                                                                                                                       |
| Scheme       | ANY                                                                                                                   |
| Method       | ANY                                                                                                                   |
| Requirements | voucher: \d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}                                    |
| Class        | Symfony\Component\Routing\Route                                                                                       |
| Defaults     | _controller: Terminal42\NotificationCenterBundle\Controller\DownloadBulkyItemController()                             |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                                                               |
|              | utf8: true                                                                                                            |
+--------------+-----------------------------------------------------------------------------------------------------------------------+

Contao 5.x:

$ bin/console debug:router nc_bulky_item_download
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Property     | Value                                                                                                                 |
+--------------+-----------------------------------------------------------------------------------------------------------------------+
| Route Name   | nc_bulky_item_download                                                                                                |
| Path         | /notifications/download/{voucher}                                                                                     |
| Path Regex   | {^/notifications/download/(?P<voucher>\d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12})$}sDu |
| Host         | ANY                                                                                                                   |
| Host Regex   |                                                                                                                       |
| Scheme       | ANY                                                                                                                   |
| Method       | ANY                                                                                                                   |
| Requirements | voucher: \d{8}/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}                                    |
| Class        | Symfony\Component\Routing\Route                                                                                       |
| Defaults     | _controller: Terminal42\NotificationCenterBundle\Controller\DownloadBulkyItemController()                             |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                                                               |
|              | utf8: true                                                                                                            |
+--------------+-----------------------------------------------------------------------------------------------------------------------+

@fritzmg fritzmg added the bug label Nov 28, 2024
@fritzmg fritzmg self-assigned this Nov 28, 2024
@Toflar Toflar requested a review from aschempp December 3, 2024 15:15
@aschempp
Copy link
Member

aschempp commented Dec 3, 2024

Does this have any advantages over the current implementation? Also using a deprecated class that will likely be dropped in Symfony 8?

@fritzmg
Copy link
Collaborator Author

fritzmg commented Dec 3, 2024

At the moment there is no real advantage, other than having an example to look at in a popular repository. It would be more advantageous once you need more controllers/routes.

The Symfony\Component\Routing\Annotation\Route class is not deprecated.

@aschempp
Copy link
Member

Closing this because I think using a config file for route loading is perfectly fine, and superior to kernel-version handling because of PHP side-effects like attributes vs. annotations.

@aschempp aschempp closed this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants