Apply tags, autowire or method setup for specfic class types. E.g.:
- add "console.command" tag to every
Symfony\Component\Console\Command\Command
class - add "kernel.event_subscriber" for every class, that implements
Symfony\Component\EventDispatcher\EventSubscriberInterface
- turn autowire on for all controllers that extends
Symfony\Bundle\FrameworkBundle\Controller\Controller
Inspired by Nette Decorator feature.
composer require symplify/service-definition-decorator
Add bundle to AppKernel.php
:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symplify\ServiceDefinitionDecorator\Symfony\SymplifyServiceDefinitionDecorator(),
// ...
];
}
}
In general, there are 3 feature to use:
decorator:
"class/interface type to decorate":
tags:
- "tags to apply"
autowire: true # turn autowiring on
calls:
- ["setterMethod", ["argument/service to be set"]]
The most common use cases to start with:
# app/config/config.yml
decorator:
Symfony\Component\Console\Command\Command:
tags:
- { name: "console.command" }
Symfony\Component\EventDispatcher\EventSubscriberInterface:
autowire: true
tags:
- { name: "kernel.event_subscriber" }
Symplify\ServiceDefinitionDecorator\Tests\Adapter\Symfony\Source\DummyServiceAwareInterface:
calls:
- [setDummyService, ['@dummy_service']]
That's all :)
Send issue or pull-request to main repository.