From 46981e74265af313c8965b13938beaf7008ff196 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 5 Mar 2023 09:47:09 +0100 Subject: [PATCH] [Attributes] Add attributes overview --- components/serializer.rst | 8 ++ console.rst | 6 +- event_dispatcher.rst | 2 + reference/attributes.rst | 77 +++++++++++++++++++ reference/map.rst.inc | 1 + serializer.rst | 2 + service_container.rst | 2 + service_container/autowiring.rst | 2 + .../service_subscribers_locators.rst | 4 + service_container/tags.rst | 4 + 10 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 reference/attributes.rst diff --git a/components/serializer.rst b/components/serializer.rst index 347d04dd72f..4034de81a5e 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -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 ------------------- @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -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 ---------------------------- @@ -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 ------------------------------------------- diff --git a/console.rst b/console.rst index 256cfc5d403..1e13234ecd0 100644 --- a/console.rst +++ b/console.rst @@ -217,6 +217,8 @@ available in the ``configure()`` method:: } } +.. _console_registering-the-command: + Registering the Command ~~~~~~~~~~~~~~~~~~~~~~~ @@ -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' => '']); diff --git a/event_dispatcher.rst b/event_dispatcher.rst index 434d0f409e3..7f9adf284bc 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/reference/attributes.rst b/reference/attributes.rst new file mode 100644 index 00000000000..98404e5c9f2 --- /dev/null +++ b/reference/attributes.rst @@ -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 ` + +Command +~~~~~~~ + +* :ref:`AsCommand ` + +Contracts +~~~~~~~~~ + +* :ref:`Required ` +* :ref:`SubscribedService ` + +Dependency Injection +~~~~~~~~~~~~~~~~~~~~ + +* :ref:`AsTaggedItem ` +* :ref:`Autoconfigure ` +* :ref:`AutoconfigureTag ` +* :ref:`TaggedIterator ` +* :ref:`TaggedLocator ` +* :ref:`Target ` +* :ref:`When ` + +EventDispatcher +~~~~~~~~~~~~~~~ + +* :ref:`AsEventListener ` + +HttpKernel +~~~~~~~~~~ + +* :doc:`AsController ` + +Messenger +~~~~~~~~~ + +* :ref:`AsMessageHandler ` + +Routing +~~~~~~~ + +* :doc:`Route ` + +Security +~~~~~~~~ + +* :ref:`CurrentUser ` + +Serializer +~~~~~~~~~~ + +* :ref:`Context ` +* :ref:`DiscriminatorMap ` +* :ref:`Groups ` +* :ref:`Ignore ` +* :ref:`MaxDepth ` +* :ref:`SerializedName ` + +Validator +~~~~~~~~~ + +Each validation constraint comes with a PHP attribute. See +:doc:`/reference/constraints` for a full list of validation constraints. diff --git a/reference/map.rst.inc b/reference/map.rst.inc index 2be47a8a0b0..0943b43dda9 100644 --- a/reference/map.rst.inc +++ b/reference/map.rst.inc @@ -36,4 +36,5 @@ Others * :doc:`Configuring the Kernel ` * :doc:`Twig Extensions (forms, filters, tags, etc) Reference ` * :doc:`/reference/dic_tags` +* :doc:`Symfony Attributes Overview ` * :doc:`/reference/events` diff --git a/serializer.rst b/serializer.rst index 0a1409de2b5..d02dc302e56 100644 --- a/serializer.rst +++ b/serializer.rst @@ -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 ------------------ diff --git a/service_container.rst b/service_container.rst index c9628c19628..5b2321bfbaa 100644 --- a/service_container.rst +++ b/service_container.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 86010b94bc9..0d0a3d27398 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -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 ------------------------------------------------------ diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst index e60cb8686b0..d7d59984032 100644 --- a/service_container/service_subscribers_locators.rst +++ b/service_container/service_subscribers_locators.rst @@ -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 -------------------------- @@ -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 ------------------------ diff --git a/service_container/tags.rst b/service_container/tags.rst index d948dde300b..7c8947c2e6b 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1013,6 +1015,8 @@ array element. For example, to retrieve the ``handler_two`` handler:: ; }; +.. _tags_as-tagged-item: + The ``#[AsTaggedItem]`` attribute ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~