Skip to content

Commit da9ed98

Browse files
authored
Update tags.rst
I think it's the new recommanded way for bundles (as seen here https://symfony.com/doc/current/bundles/extension.html)
1 parent bfd060d commit da9ed98

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

service_container/tags.rst

+19
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ In a Symfony bundle, call this method in the ``load()`` method of the
171171
}
172172
}
173173

174+
or if you are following the recommended way for new bundles and for bundles following the
175+
:ref:`recommended directory structure <bundles-directory-structure>`::
176+
177+
// ...
178+
use Symfony\Component\DependencyInjection\ContainerBuilder;
179+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
180+
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
181+
182+
class MyBundle extends AbstractBundle
183+
{
184+
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
185+
{
186+
$builder
187+
->registerForAutoconfiguration(CustomInterface::class)
188+
->addTag('app.custom_tag')
189+
;
190+
}
191+
}
192+
174193
Autoconfiguration registering is not limited to interfaces. It is possible
175194
to use PHP attributes to autoconfigure services by using the
176195
:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::registerAttributeForAutoconfiguration`

0 commit comments

Comments
 (0)