forked from phpstan/phpstan-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleServiceTraitSubscriber.php
70 lines (57 loc) · 1.66 KB
/
ExampleServiceTraitSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Rules\Symfony;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\Service\Attribute\SubscribedService;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\Contracts\Service\ServiceSubscriberTrait;
final class ExampleServiceTraitSubscriber implements ServiceSubscriberInterface
{
use ServiceSubscriberTrait;
/** @var ContainerInterface */
private $locator;
public function __construct(ContainerInterface $locator)
{
$this->locator = $locator;
}
#[SubscribedService(attributes: new Autowire('private'))]
private function getIndexed(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService(attributes: new Autowire(value: 'private'))]
private function getNamedValue(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService(attributes: new Autowire(service: 'private'))]
private function getNamedService(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService(attributes: new Autowire('unknown'))]
private function getUnknownIndexed(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService(attributes: new Autowire(value: 'unknown'))]
private function getUnknownNamedValue(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService(attributes: new Autowire(service: 'unknown'))]
private function getUnknownNamedService(): Foo
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService]
public function getBar(): \Bar
{
return $this->locator->get(__METHOD__);
}
#[SubscribedService]
public function getBaz(): \Baz
{
return $this->locator->get(__METHOD__);
}
}