Skip to content

[Attributes] Add attributes overview #18003

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
Mar 7, 2023
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
8 changes: 8 additions & 0 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ If some serialization groups are set, only attributes allowed by those groups ca

As for groups, attributes can be selected during both the serialization and deserialization process.

.. _serializer_ignoring-attributes:

Ignoring Attributes
-------------------

Expand Down Expand Up @@ -677,6 +679,8 @@ processes::
$anne = $normalizer->denormalize(['first_name' => 'Anne'], 'Person');
// Person object with firstName: 'Anne'

.. _serializer_name-conversion:

Configure name conversion using metadata
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1436,6 +1440,8 @@ having unique identifiers::
var_dump($serializer->serialize($org, 'json'));
// {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}

.. _serializer_handling-serialization-depth:

Handling Serialization Depth
----------------------------

Expand Down Expand Up @@ -1751,6 +1757,8 @@ will be thrown. The type enforcement of the properties can be disabled by settin
the serializer context option ``ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT``
to ``true``.

.. _serializer_interfaces-and-abstract-classes:

Serializing Interfaces and Abstract Classes
-------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ available in the ``configure()`` method::
}
}

.. _console_registering-the-command:

Registering the Command
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -548,13 +550,13 @@ call ``setAutoExit(false)`` on it to get the command result in ``CommandTester``
$application->setAutoExit(false);

$tester = new ApplicationTester($application);


.. caution::

When testing ``InputOption::VALUE_NONE`` command options, you must pass an
empty value to them::

$commandTester = new CommandTester($command);
$commandTester->execute(['--some-option' => '']);

Expand Down
2 changes: 2 additions & 0 deletions event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ listener class:
method (which makes event listeners invokable);
#. If the ``__invoke()`` method is not defined either, throw an exception.

.. _event-dispatcher_event-listener-attributes:

Defining Event Listeners with PHP Attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
77 changes: 77 additions & 0 deletions reference/attributes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.. index::
single: Attributes

Symfony Attributes Overview
===========================

Attributes are the successor of annotation since PHP 8. Attributes are native
to the language and Symfony takes full advantage of them across the framework
ans its different components.

Doctrine Bridge
~~~~~~~~~~~~~~~

* :doc:`UniqueEntity </reference/constraints/UniqueEntity>`

Command
~~~~~~~

* :ref:`AsCommand <console_registering-the-command>`

Contracts
~~~~~~~~~

* :ref:`Required <autowiring-calls>`
* :ref:`SubscribedService <service-subscribers-service-subscriber-trait>`

Dependency Injection
~~~~~~~~~~~~~~~~~~~~

* :ref:`AsTaggedItem <tags_as-tagged-item>`
* :ref:`Autoconfigure <lazy-services_configuration>`
* :ref:`AutoconfigureTag <di-instanceof>`
* :ref:`TaggedIterator <tags_reference-tagged-services>`
* :ref:`TaggedLocator <service-subscribers-locators_defining-service-locator>`
* :ref:`Target <autowiring-multiple-implementations-same-type>`
* :ref:`When <service-container_limiting-to-env>`

EventDispatcher
~~~~~~~~~~~~~~~

* :ref:`AsEventListener <event-dispatcher_event-listener-attributes>`

HttpKernel
~~~~~~~~~~

* :doc:`AsController </controller/service>`

Messenger
~~~~~~~~~

* :ref:`AsMessageHandler <messenger-handler>`

Routing
~~~~~~~

* :doc:`Route </routing>`

Security
~~~~~~~~

* :ref:`CurrentUser <security-json-login>`

Serializer
~~~~~~~~~~

* :ref:`Context <serializer_serializer-context>`
* :ref:`DiscriminatorMap <serializer_interfaces-and-abstract-classes>`
* :ref:`Groups <component-serializer-attributes-groups-annotations>`
* :ref:`Ignore <serializer_ignoring-attributes>`
* :ref:`MaxDepth <serializer_handling-serialization-depth>`
* :ref:`SerializedName <serializer_name-conversion>`

Validator
~~~~~~~~~

Each validation constraint comes with a PHP attribute. See
:doc:`/reference/constraints` for a full list of validation constraints.
1 change: 1 addition & 0 deletions reference/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Others
* :doc:`Configuring the Kernel </reference/configuration/kernel>`
* :doc:`Twig Extensions (forms, filters, tags, etc) Reference </reference/twig_reference>`
* :doc:`/reference/dic_tags`
* :doc:`Symfony Attributes Overview </reference/attributes>`
* :doc:`/reference/events`
2 changes: 2 additions & 0 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ possible to set the priority of the tag in order to decide the matching order.
``DateTime`` or ``DateTimeImmutable`` classes to avoid excessive memory
usage and exposing internal details.

.. _serializer_serializer-context:

Serializer Context
------------------

Expand Down
2 changes: 2 additions & 0 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ each time you ask for it.
If you'd prefer to manually wire your service, that's totally possible: see
:ref:`services-explicitly-configure-wire-services`.

.. _service-container_limiting-to-env:

Limiting Services to a specific Symfony Environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions service_container/autowiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ dealing with the ``TransformerInterface``.

The support of union and intersection types was introduced in Symfony 5.4.

.. _autowiring-multiple-implementations-same-type:

Dealing with Multiple Implementations of the Same Type
------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions service_container/service_subscribers_locators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ service type to a service.
The ``key`` attribute can be omitted if the service name internally is the
same as in the service container.

.. _service-subscribers-locators_defining-service-locator:

Defining a Service Locator
--------------------------

Expand Down Expand Up @@ -695,6 +697,8 @@ attribute to the locator service defining the name of this custom method:
going to be used, a configuration key (``key`` in the example above) must
be set so the custom method may be called as a fallback.

.. _service-subscribers-service-subscriber-trait:

Service Subscriber Trait
------------------------

Expand Down
4 changes: 4 additions & 0 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ than one tag. You tag a service twice or more with the ``app.mail_transport``
tag. The second ``foreach`` loop iterates over the ``app.mail_transport``
tags set for the current service and gives you the attributes.

.. _tags_reference-tagged-services:

Reference Tagged Services
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1013,6 +1015,8 @@ array element. For example, to retrieve the ``handler_two`` handler::
;
};

.. _tags_as-tagged-item:

The ``#[AsTaggedItem]`` attribute
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down