Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Add autoconfigure tag for ParamConverterInterface #516

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions DependencyInjection/SensioFrameworkExtraExtension.php
Expand Up @@ -11,6 +11,7 @@

namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection;

use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -47,6 +48,9 @@ public function load(array $configs, ContainerBuilder $container)
if ($config['request']['converters']) {
$annotationsToLoad[] = 'converters.xml';

$container->registerForAutoconfiguration(ParamConverterInterface::class)
->addTag('request.param_converter');

$container->setParameter('sensio_framework_extra.disabled_converters', is_string($config['request']['disable']) ? implode(',', $config['request']['disable']) : $config['request']['disable']);

$container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
Expand Down
6 changes: 5 additions & 1 deletion Resources/doc/annotations/converters.rst
Expand Up @@ -296,7 +296,9 @@ on the request attributes, it should set an attribute named
``$configuration->getName()``, which stores an object of class
``$configuration->getClass()``.

To register your converter service, you must add a tag to your service:
If you're using service `auto-registration and autoconfiguration`_,
you're done! Your converter will automatically be used.
If not, you must add a tag to your service:

.. configuration-block::

Expand Down Expand Up @@ -330,3 +332,5 @@ definition.
.. tip::

Use the ``DoctrineParamConverter`` class as a template for your own converters.

.. _auto-registration and autoconfiguration: http://symfony.com/doc/current/service_container/3.3-di-changes.html