Skip to content

Commit 7cfdbfc

Browse files
committed
feature #14230 [Routing] Document the Route attribute (derrabus)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- [Routing] Document the Route attribute This PR documents the new `#[Route]` attribute that was introduced with symfony/symfony#37474 and thus closes #14188. For the routing configuration via Doctrine Annotations as well as PHP attributes, we use the very same class, `Symfony\Component\Routing\Annotation\Route`. This means that both mechanisms are equally powerful. Right now, there's nothing you can do with `@Route` that is impossible with `#[Route]` and vice versa. The main difference is that you don't need an external library for attributes because they're a native language feature. Because of that, I'd like to shift the general recommendation to use annotation towards attributes and recommend annotations as the fallback for projects that need to remain compatible with PHP 7. Right now, the `@Route` annotation is used throughout the documentation in two different ways: 1. Demonstrate how to use the annotation In this case, I've added an additional code block that shows the same configuration for attributes. I've consistently placed the attribute block before the annotation block. 2. Give context about the route configuration. When a code block illustrates the logic inside a controller action and the annotation is only used to provide context, I think it would create too much noise to show the attribute _and_ the annotation way. In `routing.rst`, I have replaced the annotation with an equal attribute in such cases. I think it would be a good idea to do the same with the rest of the documentation, but I'd like to discuss this with you before I change all those spots. Commits ------- 4ca794e [Routing] Document the Route attribute
2 parents 39eec8b + 4ca794e commit 7cfdbfc

File tree

4 files changed

+446
-50
lines changed

4 files changed

+446
-50
lines changed

_build/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
lexers['markdown'] = TextLexer()
112112
lexers['php'] = PhpLexer(startinline=True)
113113
lexers['php-annotations'] = PhpLexer(startinline=True)
114+
lexers['php-attributes'] = PhpLexer(startinline=True)
114115
lexers['php-standalone'] = PhpLexer(startinline=True)
115116
lexers['php-symfony'] = PhpLexer(startinline=True)
116117
lexers['rst'] = RstLexer()

best_practices.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ important parts of your application.
223223

224224
.. _best-practice-controller-annotations:
225225

226-
Use Annotations to Configure Routing, Caching and Security
227-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226+
Use Attributes or Annotations to Configure Routing, Caching and Security
227+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228228

229-
Using annotations for routing, caching and security simplifies configuration.
230-
You don't need to browse several files created with different formats (YAML, XML,
231-
PHP): all the configuration is just where you need it and it only uses one format.
229+
Using attributes or annotations for routing, caching and security simplifies
230+
configuration. You don't need to browse several files created with different
231+
formats (YAML, XML, PHP): all the configuration is just where you need it and
232+
it only uses one format.
232233

233234
Don't Use Annotations to Configure the Controller Template
234235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

contributing/documentation/format.rst

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Markup Format Use It to Display
104104
``html+php`` PHP code blended with HTML
105105
``ini`` INI
106106
``php-annotations`` PHP Annotations
107+
``php-attributes`` PHP Attributes
107108
=================== ======================================
108109

109110
Adding Links

0 commit comments

Comments
 (0)