Skip to content

Commit

Permalink
[Documentation] Deprecate annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Jul 21, 2023
1 parent db49e10 commit 0380429
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 119 deletions.
11 changes: 4 additions & 7 deletions best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ Doctrine supports several metadata formats, but it's recommended to use PHP
attributes because they are by far the most convenient and agile way of setting
up and looking for mapping information.

If your PHP version doesn't support attributes yet, use annotations, which is
similar but requires installing some extra dependencies in your project.

Controllers
-----------

Expand All @@ -226,12 +223,12 @@ controllers shouldn't contain any business logic. Controllers should contain
nothing more than a few lines of *glue-code*, so you are not coupling the
important parts of your application.

.. _best-practice-controller-annotations:
.. _best-practice-controller-attributes:

Use Attributes or Annotations to Configure Routing, Caching, and Security
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use Attributes to Configure Routing, Caching, and Security
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using attributes or annotations for routing, caching, and security simplifies
Using attributes for routing, caching, and security simplifies
configuration. You don't need to browse several files created with different
formats (YAML, XML, PHP): all the configuration is just where you require it,
and it only uses one format.
Expand Down
6 changes: 3 additions & 3 deletions bundles/best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ Event Listeners ``src/EventListener/``
Configuration (routes, services, etc.) ``config/``
Web Assets (CSS, JS, images) ``public/``
Translation files ``translations/``
Validation (when not using annotations) ``config/validation/``
Serialization (when not using annotations) ``config/serialization/``
Validation (when not using attributes) ``config/validation/``
Serialization (when not using attributes) ``config/serialization/``
Templates ``templates/``
Unit and Functional Tests ``tests/``
=================================================== ========================================
Expand Down Expand Up @@ -163,7 +163,7 @@ If the bundle includes Doctrine ORM entities and/or ODM documents, it's
recommended to define their mapping using XML files stored in
``config/doctrine/``. This allows to override that mapping using the
:doc:`standard Symfony mechanism to override bundle parts </bundles/override>`.
This is not possible when using annotations/attributes to define the mapping.
This is not possible when using attributes to define the mapping.

Tests
-----
Expand Down
2 changes: 1 addition & 1 deletion components/config/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ an array containing all matches.
Resource Loaders
----------------

For each type of resource (YAML, XML, annotation, etc.) a loader must be
For each type of resource (YAML, XML, attributes, etc.) a loader must be
defined. Each loader should implement
:class:`Symfony\\Component\\Config\\Loader\\LoaderInterface` or extend the
abstract :class:`Symfony\\Component\\Config\\Loader\\FileLoader` class,
Expand Down
6 changes: 3 additions & 3 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ for each format:

$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));

.. _component-serializer-attributes-groups-annotations:
.. _component-serializer-attributes-groups-attributes:

Then, create your groups definition:

Expand Down Expand Up @@ -436,8 +436,8 @@ Ignoring Attributes
All attributes are included by default when serializing objects. There are two
options to ignore some of those attributes.

Option 1: Using ``@Ignore`` Annotation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option 1: Using ``#[Ignore]`` Attribute
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. configuration-block::

Expand Down
4 changes: 4 additions & 0 deletions components/validator/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ If you use annotations instead of attributes, it's also required to call
->addDefaultDoctrineAnnotationReader() // add this only when using annotations
->getValidator();

.. deprecated:: 6.4

Annotations are deprecated since Symfony 6.4, use attributes instead.

To disable the annotation loader after it was enabled, call
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::disableAnnotationMapping`.

Expand Down
4 changes: 2 additions & 2 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Before continuing, run this command to add support for the new dependencies:

.. code-block:: terminal
$ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle doctrine/annotations
$ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle
Next, create a new extension class that defines your app configuration and
add a service conditionally based on the ``foo`` value::
Expand Down Expand Up @@ -377,7 +377,7 @@ because the configuration started to get bigger:
;
};
This also loads annotation routes from an ``src/Controller/`` directory, which
This also loads attribute routes from an ``src/Controller/`` directory, which
has one file in it::

// src/Controller/MicroController.php
Expand Down
2 changes: 1 addition & 1 deletion configuration/multiple_kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ resources::
}

if (false !== ($fileName = (new \ReflectionObject($this))->getFileName())) {
$routes->import($fileName, 'annotation');
$routes->import($fileName, 'attribute');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Mapping a URL to a Controller

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

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

Expand Down
2 changes: 1 addition & 1 deletion controller/upload_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ so Symfony doesn't try to get/set its value from the related entity::
// every time you edit the Product details
'required' => false,

// unmapped fields can't define their validation using annotations
// unmapped fields can't define their validation using attributes
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
Expand Down
4 changes: 2 additions & 2 deletions doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ add/remove fields, add/remove methods or update configuration.

Doctrine supports a wide variety of field types, each with their own options.
To see a full list, check out `Doctrine's Mapping Types documentation`_.
If you want to use XML instead of annotations, add ``type: xml`` and
If you want to use XML instead of attributes, add ``type: xml`` and
``dir: '%kernel.project_dir%/config/doctrine'`` to the entity mappings in your
``config/packages/doctrine.yaml`` file.

Expand Down Expand Up @@ -746,7 +746,7 @@ the default convention.
MapEntity Options
~~~~~~~~~~~~~~~~~

A number of options are available on the ``MapEntity`` annotation to
A number of options are available on the ``MapEntity`` attribute to
control behavior:

``id``
Expand Down
2 changes: 1 addition & 1 deletion doctrine/associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ From the perspective of the ``Product`` entity, this is a many-to-one relationsh
From the perspective of the ``Category`` entity, this is a one-to-many relationship.

To map this, first create a ``category`` property on the ``Product`` class with
the ``ManyToOne`` annotation. You can do this by hand, or by using the ``make:entity``
the ``ManyToOne`` attribute. You can do this by hand, or by using the ``make:entity``
command, which will ask you several questions about your relationship. If you're
not sure of the answer, don't worry! You can always change the settings later:

Expand Down
1 change: 0 additions & 1 deletion form/unit_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ allows you to return a list of extensions to register::
// or if you also need to read constraints from annotations
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping(true)
->addDefaultDoctrineAnnotationReader()
->getValidator();

return [
Expand Down
2 changes: 1 addition & 1 deletion page_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ random) number and prints it. To do that, create a "Controller" class and a
}
}

.. _annotation-routes:
.. _attribute-routes:

Now you need to associate this controller function with a public URL (e.g. ``/lucky/number``)
so that the ``number()`` method is called when a user browses to it. This association
Expand Down
9 changes: 2 additions & 7 deletions quick_tour/the_big_picture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,8 @@ Try the page out by going to ``http://localhost:8000/hello/Symfony``. You should
see: Hello Symfony! The value of the ``{name}`` in the URL is available as a ``$name``
argument in your controller.

But this can be even simpler! So let's install annotations support:

.. code-block:: terminal
$ composer require annotations
Now, comment-out the YAML route by adding the ``#`` character:
But this can be even simpler! Comment-out the YAML route by adding the
``#`` character:

.. code-block:: yaml
Expand Down
9 changes: 7 additions & 2 deletions reference/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Attributes are the successor of annotations since PHP 8. Attributes are native
to the language and Symfony takes full advantage of them across the framework
and its different components.

.. deprecated:: 6.4

Annotations across the framework are deprecated since Symfony 6.4, you must
only use attributes instead.

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

Expand Down Expand Up @@ -78,14 +83,14 @@ Security
~~~~~~~~

* :ref:`CurrentUser <security-json-login>`
* :ref:`IsGranted <security-securing-controller-annotations>`
* :ref:`IsGranted <security-securing-controller-attributes>`

Serializer
~~~~~~~~~~

* :ref:`Context <serializer_serializer-context>`
* :ref:`DiscriminatorMap <serializer_interfaces-and-abstract-classes>`
* :ref:`Groups <component-serializer-attributes-groups-annotations>`
* :ref:`Groups <component-serializer-attributes-groups-attributes>`
* :ref:`Ignore <serializer_ignoring-attributes>`
* :ref:`MaxDepth <serializer_handling-serialization-depth>`
* :ref:`SerializedName <serializer_name-conversion>`
Expand Down
16 changes: 10 additions & 6 deletions reference/configuration/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ One of ``annotation`` (for PHP annotations; it's the default value),
``attribute`` (for PHP attributes), ``xml``, ``yml``, ``php`` or
``staticphp``. This specifies which type of metadata type your mapping uses.

.. deprecated:: 6.4

Annotations are deprecated since Symfony 6.4, use attributes instead.

See `Doctrine Metadata Drivers`_ for more information about this option.

``dir``
Expand Down Expand Up @@ -385,7 +389,7 @@ namespace in the ``src/Entity`` directory and gives them an ``App`` alias
mappings:
# ...
SomeEntityNamespace:
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
is_bundle: false
prefix: App\Entity
Expand All @@ -403,7 +407,7 @@ namespace in the ``src/Entity`` directory and gives them an ``App`` alias
<doctrine:config>
<doctrine:orm>
<mapping name="SomeEntityNamespace"
type="annotation"
type="attribute"
dir="%kernel.project_dir%/src/Entity"
is-bundle="false"
prefix="App\Entity"
Expand All @@ -422,7 +426,7 @@ namespace in the ``src/Entity`` directory and gives them an ``App`` alias
$emDefault->autoMapping(true);
$emDefault->mapping('SomeEntityNamespace')
->type('annotation')
->type('attribute')
->dir('%kernel.project_dir%/src/Entity')
->isBundle(false)
->prefix('App\Entity')
Expand All @@ -446,14 +450,14 @@ configuration format. The bundle will stop as soon as it locates one.

If it wasn't possible to determine a configuration format for a bundle,
the DoctrineBundle will check if there is an ``Entity`` folder in the bundle's
root directory. If the folder exist, Doctrine will fall back to using an
annotation driver.
root directory. If the folder exist, Doctrine will fall back to using
attributes.

Default Value of Dir
....................

If ``dir`` is not specified, then its default value depends on which configuration
driver is being used. For drivers that rely on the PHP files (annotation,
driver is being used. For drivers that rely on the PHP files (attribute,
``staticphp``) it will be ``[Bundle]/Entity``. For drivers that are using
configuration files (XML, YAML, ...) it will be
``[Bundle]/Resources/config/doctrine``.
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/DisableAutoMapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DisableAutoMapping

This constraint allows to disable :ref:`Doctrine's auto mapping <doctrine_auto-mapping>`
on a class or a property. Automapping allows to determine validation rules based
on Doctrine's annotations and attributes. You may use this constraint when
on Doctrine's attributes. You may use this constraint when
automapping is globally enabled, but you still want to disable this feature for
a class or a property specifically.

Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/EnableAutoMapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ EnableAutoMapping

This constraint allows to enable :ref:`Doctrine's auto mapping <doctrine_auto-mapping>`
on a class or a property. Automapping allows to determine validation rules based
on Doctrine's annotations and attributes. You may use this constraint when
on Doctrine's attributes. You may use this constraint when
automapping is globally disabled, but you still want to enable this feature for
a class or a property specifically.

Expand Down
Loading

0 comments on commit 0380429

Please sign in to comment.