Skip to content

Replace Route annotations with attributes, remove Route annotation configuration block #17142

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

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ has one file in it::

class MicroController extends AbstractController
{
/**
* @Route("/random/{limit}")
*/
#[Route('/random/{limit}')]
public function randomNumber(int $limit): Response
{
$number = random_int(0, $limit);
Expand Down
37 changes: 0 additions & 37 deletions controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ a service like: ``App\Controller\HelloController::index``:

.. configuration-block::

.. code-block:: php-annotations

// src/Controller/HelloController.php
namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;

class HelloController
{
/**
* @Route("/hello", name="hello", methods={"GET"})
*/
public function index()
{
// ...
}
}

.. code-block:: php-attributes

// src/Controller/HelloController.php
Expand Down Expand Up @@ -118,25 +100,6 @@ which is a common practice when following the `ADR pattern`_

.. configuration-block::

.. code-block:: php-annotations

// src/Controller/Hello.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/hello/{name}", name="hello")
*/
class Hello
{
public function __invoke($name = 'World')
{
return new Response(sprintf('Hello %s!', $name));
}
}

.. code-block:: php-attributes

// src/Controller/Hello.php
Expand Down
4 changes: 1 addition & 3 deletions controller/soap_web_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ can be retrieved via ``/soap?wsdl``::

class HelloServiceController extends AbstractController
{
/**
* @Route("/soap")
*/
#[Route('/soap')]
public function index(HelloService $helloService)
{
$soapServer = new \SoapServer('/path/to/hello.wsdl');
Expand Down
4 changes: 1 addition & 3 deletions controller/upload_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ Finally, you need to update the code of the controller that handles the form::

class ProductController extends AbstractController
{
/**
* @Route("/product/new", name="app_product_new")
*/
#[Route('/product/new', name: 'app_product_new')]
public function new(Request $request, SluggerInterface $slugger)
{
$product = new Product();
Expand Down
8 changes: 2 additions & 6 deletions lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ To lock the default resource, autowire the lock factory using

class PdfController extends AbstractController
{
/**
* @Route("/download/terms-of-use.pdf")
*/
#[Route('/download/terms-of-use.pdf')]
public function downloadPdf(LockFactory $factory, MyPdfGeneratorService $pdf)
{
$lock = $factory->createLock('pdf-creation');
Expand Down Expand Up @@ -212,9 +210,7 @@ processes asking for the same ``$version``::

class PdfController extends AbstractController
{
/**
* @Route("/download/{version}/terms-of-use.pdf")
*/
#[Route('/download/{version}/terms-of-use.pdf')]
public function downloadPdf($version, LockFactory $lockFactory, MyPdfGeneratorService $pdf)
{
$lock = $lockFactory->createLock($version);
Expand Down
4 changes: 1 addition & 3 deletions notifier/chatters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ you to send messages to chat services like Slack or Telegram::

class CheckoutController extends AbstractController
{
/**
* @Route("/checkout/thankyou")
*/
#[Route('/checkout/thankyou')]
public function thankyou(ChatterInterface $chatter)
{
$message = (new ChatMessage('You got a new invoice for 15 EUR.'))
Expand Down
4 changes: 1 addition & 3 deletions notifier/texters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ you to send SMS messages::

class SecurityController
{
/**
* @Route("/login/success")
*/
#[Route('/login/success')]
public function loginSuccess(TexterInterface $texter)
{
$sms = new SmsMessage(
Expand Down
22 changes: 1 addition & 21 deletions page_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,6 @@ You can now add your route directly *above* the controller:

.. configuration-block::

.. code-block:: php-annotations

// src/Controller/LuckyController.php

// ...
+ use Symfony\Component\Routing\Annotation\Route;

class LuckyController
{
+ /**
+ * @Route("/lucky/number")
+ */
public function number(): Response
{
// this looks exactly the same
}
}

.. code-block:: php-attributes

// src/Controller/LuckyController.php
Expand Down Expand Up @@ -257,9 +239,7 @@ variable so you can use it in Twig::

class LuckyController extends AbstractController
{
/**
* @Route("/lucky/number")
*/
#[Route('/lucky/number')]
public function number(): Response
{
$number = random_int(0, 100);
Expand Down
8 changes: 2 additions & 6 deletions quick_tour/flex_recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ Thanks to Flex, after one command, you can start using Twig immediately:
- class DefaultController
+ class DefaultController extends AbstractController
{
/**
* @Route("/hello/{name}")
*/
#[Route('/hello/{name}')]
public function index($name)
{
- return new Response("Hello $name!");
Expand Down Expand Up @@ -165,9 +163,7 @@ Are you building an API? You can already return JSON from any controller::
{
// ...

/**
* @Route("/api/hello/{name}")
*/
#[Route('/api/hello/{name}')]
public function apiExample($name)
{
return $this->json([
Expand Down
8 changes: 2 additions & 6 deletions quick_tour/the_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ use the logger in a controller, add a new argument type-hinted with ``LoggerInte

class DefaultController extends AbstractController
{
/**
* @Route("/hello/{name}")
*/
#[Route('/hello/{name}')]
public function index($name, LoggerInterface $logger)
{
$logger->info("Saying hello to $name!");
Expand Down Expand Up @@ -115,9 +113,7 @@ Great! You can use this immediately in your controller::

class DefaultController extends AbstractController
{
/**
* @Route("/hello/{name}")
*/
#[Route('/hello/{name}')]
public function index($name, LoggerInterface $logger, GreetingGenerator $generator)
{
$greeting = $generator->getRandomGreeting();
Expand Down
10 changes: 3 additions & 7 deletions quick_tour/the_big_picture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ Instead, add the route *right above* the controller method:

class DefaultController
{
+ /**
+ * @Route("/hello/{name}")
+ */
+ #[Route('/hello/{name}')]
public function index($name) {
// ...
}
}

This works just like before! But by using annotations, the route and controller
This works just like before! But by using attributes, the route and controller
live right next to each other. Need another page? Add another route and method
in ``DefaultController``::

Expand All @@ -187,9 +185,7 @@ in ``DefaultController``::
{
// ...

/**
* @Route("/simplicity")
*/
#[Route('/simplicity')]
public function simple()
{
return new Response('Simple! Easy! Great!');
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ the data can be a ``DateTime`` object, a string, a timestamp or an array.
+---------------------------+-----------------------------------------------------------------------------+
| Underlying Data Type | can be ``DateTime``, string, timestamp, or array (see the ``input`` option) |
+---------------------------+-----------------------------------------------------------------------------+
| Rendered as | single text box or five select fields |
| Rendered as | single text box or five select fields |
+---------------------------+-----------------------------------------------------------------------------+
| Default invalid message | Please enter a valid date and time. |
+---------------------------+-----------------------------------------------------------------------------+
Expand Down
Loading