Skip to content
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

Add attribute support for service injection #1984

Closed
Haehnchen opened this issue Jul 21, 2022 · 0 comments
Closed

Add attribute support for service injection #1984

Haehnchen opened this issue Jul 21, 2022 · 0 comments

Comments

@Haehnchen
Copy link
Owner

Haehnchen commented Jul 21, 2022

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;
    }
}
Haehnchen added a commit that referenced this issue Jul 22, 2022
#1984 support parameters inside "Autowire" attribute
Haehnchen added a commit that referenced this issue Jul 22, 2022
…ttribute

#1984 support parameter inside "TaggedIterator" attribute
Haehnchen added a commit that referenced this issue Jul 23, 2022
…te-service

#1984 support service inside "Autowire" attribute
Haehnchen added a commit that referenced this issue Jul 23, 2022
…-attribute

#1984 detected missing services inside "Autowire" attribute
Haehnchen added a commit that referenced this issue Jul 23, 2022
#1984 detected deprecated services usage inside "Autowire" attribute
Haehnchen added a commit that referenced this issue Jul 23, 2022
#1984 support parameter inside "TaggedLocator" attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant