Skip to content

Add documentation to use AsTaggedItem for value resolver priority/name #20896

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

Open
wants to merge 2 commits into
base: 6.4
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions controller/value_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ this argument) or an array with the resolved value(s). Usually arguments are
resolved as a single value, but variadic arguments require resolving multiple
values. That's why you must always return an array, even for single values::

// src/ValueResolver/IdentifierValueResolver.php
// src/ValueResolver/BookingIdValueResolver.php
namespace App\ValueResolver;

use App\IdentifierInterface;
Expand Down Expand Up @@ -374,6 +374,20 @@ but you can set it yourself to change its ``priority`` or ``name`` attributes.

.. configuration-block::

.. code-block:: php-attributes

// src/ValueResolver/BookingIdValueResolver.php
namespace App\ValueResolver;

use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;

#[AsTaggedItem(name: 'booking_id', priority: 150)]
class BookingIdValueResolver implements ValueResolverInterface
{
// ...
}

.. code-block:: yaml

# config/services.yaml
Expand Down Expand Up @@ -455,7 +469,7 @@ As an alternative, you can add the
:class:`Symfony\\Component\\HttpKernel\\Attribute\\AsTargetedValueResolver` attribute
to your resolver and pass your custom name as its first argument::

// src/ValueResolver/IdentifierValueResolver.php
// src/ValueResolver/BookingIdValueResolver.php
namespace App\ValueResolver;

use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
Expand Down