Skip to content

Commit 4d62bf3

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Add some needed internal reference Replace annotations by attributes in Serializer and Controller
2 parents f3db711 + aa7164d commit 4d62bf3

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

components/property_info.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ SerializerExtractor
453453

454454
This extractor depends on the `symfony/serializer`_ library.
455455

456-
Using :ref:`groups metadata <serializer-using-serialization-groups-annotations>`
456+
Using :ref:`groups metadata <serializer-using-serialization-groups-attributes>`
457457
from the :doc:`Serializer component </components/serializer>`,
458458
the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor`
459459
provides list information. This extractor is *not* registered automatically

controller.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class::
3333

3434
class LuckyController
3535
{
36-
/**
37-
* @Route("/lucky/number/{max}", name="app_lucky_number")
38-
*/
36+
#[Route('/lucky/number/{max}', name: 'app_lucky_number')]
3937
public function number(int $max): Response
4038
{
4139
$number = random_int(0, $max);
@@ -73,8 +71,8 @@ Mapping a URL to a Controller
7371
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7472

7573
In order to *view* the result of this controller, you need to map a URL to it via
76-
a route. This was done above with the ``@Route("/lucky/number/{max}")``
77-
:ref:`route annotation <annotation-routes>`.
74+
a route. This was done above with the ``#[Route('/lucky/number/{max}')]``
75+
:ref:`route attribute <annotation-routes>`.
7876

7977
To see your page, go to this URL in your browser: http://localhost:8000/lucky/number/100
8078

@@ -205,9 +203,7 @@ If you need a service in a controller, type-hint an argument with its class
205203
use Symfony\Component\HttpFoundation\Response;
206204
// ...
207205

208-
/**
209-
* @Route("/lucky/number/{max}")
210-
*/
206+
#[Route('/lucky/number/{max}')]
211207
public function number(int $max, LoggerInterface $logger): Response
212208
{
213209
$logger->info('We are logging!');

reference/configuration/framework.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ If this option is enabled, serialization groups can be defined using annotations
26912691

26922692
.. seealso::
26932693

2694-
For more information, see :ref:`serializer-using-serialization-groups-annotations`.
2694+
For more information, see :ref:`serializer-using-serialization-groups-attributes`.
26952695

26962696
.. _reference-serializer-name_converter:
26972697

serializer.rst

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,12 @@ You can also :doc:`create your context builders </serializer/custom_context_buil
198198
to have autocompletion, validation, and documentation for your custom context values.
199199

200200
.. _serializer-using-serialization-groups-annotations:
201+
.. _serializer-using-serialization-groups-attributes:
201202

202-
Using Serialization Groups Annotations
203-
--------------------------------------
203+
Using Serialization Groups Attributes
204+
-------------------------------------
204205

205-
To use annotations, first add support for them via the SensioFrameworkExtraBundle:
206-
207-
.. code-block:: terminal
208-
209-
$ composer require sensio/framework-extra-bundle
210-
211-
Next, add the :ref:`@Groups annotations <component-serializer-attributes-groups-annotations>`
206+
You can add :ref:`#[Groups] attributes <component-serializer-attributes-groups-annotations>`
212207
to your class::
213208

214209
// src/Entity/Product.php
@@ -217,29 +212,21 @@ to your class::
217212
use Doctrine\ORM\Mapping as ORM;
218213
use Symfony\Component\Serializer\Annotation\Groups;
219214

220-
/**
221-
* @ORM\Entity()
222-
*/
215+
#[ORM\Entity]
223216
class Product
224217
{
225-
/**
226-
* @ORM\Id
227-
* @ORM\GeneratedValue
228-
* @ORM\Column(type="integer")
229-
* @Groups({"show_product", "list_product"})
230-
*/
218+
#[ORM\Id]
219+
#[ORM\GeneratedValue]
220+
#[ORM\Column(type: 'integer')]
221+
#[Groups(['show_product', 'list_product'])]
231222
private $id;
232223

233-
/**
234-
* @ORM\Column(type="string", length=255)
235-
* @Groups({"show_product", "list_product"})
236-
*/
224+
#[ORM\Column(type: 'string', length: 255)]
225+
#[Groups(['show_product', 'list_product'])]
237226
private $name;
238227

239-
/**
240-
* @ORM\Column(type="integer")
241-
* @Groups({"show_product"})
242-
*/
228+
#[ORM\Column(type: 'integer')]
229+
#[Groups(['show_product'])]
243230
private $description;
244231
}
245232

@@ -257,7 +244,7 @@ You can now choose which groups to use when serializing::
257244

258245
The value of the ``groups`` key can be a single string, or an array of strings.
259246

260-
In addition to the ``@Groups`` annotation, the Serializer component also
247+
In addition to the ``#[Groups]`` attribute, the Serializer component also
261248
supports YAML or XML files. These files are automatically loaded when being
262249
stored in one of the following locations:
263250

0 commit comments

Comments
 (0)