Closed
Description
use Symfony\Component\DependencyInjection\Attribute\Autowire;
class MyService
{
public function __construct(
#[Autowire(service: 'some_service')]
private $service1,
#[Autowire(expression: 'service("App\\Mail\\MailerConfiguration").getMailerMethod()')]
private $service2,
#[Autowire('%env(json:file:resolve:AUTH_FILE)%')]
private $parameter1,
#[Autowire('%kernel.project_dir%/config/dir')]
private $parameter2,
) {}
// ...
}
// src/Handler/HandlerCollection.php
namespace App\Handler;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
class HandlerCollection
{
private $handlers;
public function __construct(
#[TaggedIterator('app.handler')] iterable $handlers
) {
$this->handlers = $handlers;
}
}
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
class HandlerCollection
{
private $handlers;
public function __construct(
#[TaggedLocator('app.handler')] ContainerInterface $handlers
) {
$this->handlers = $handlers;
}
}
Metadata
Metadata
Assignees
Labels
No labels