Total Complexity | 11 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | abstract class AbstractLeagueServiceProvider extends AbstractServiceProvider |
||
9 | { |
||
10 | /** |
||
11 | * {@inheritDoc} |
||
12 | */ |
||
13 | public function provides(string $id): bool |
||
14 | { |
||
15 | return in_array($id, [ |
||
16 | $this->id(), |
||
17 | ...$this->combinedAliases(), |
||
18 | ...$this->combinedTags() |
||
19 | ]); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * {@inheritDoc} |
||
24 | */ |
||
25 | public function register(): void |
||
26 | { |
||
27 | $container = $this->getContainer(); |
||
28 | $definition = $container->add( |
||
29 | $id = $this->id(), |
||
30 | fn () => $this->service($container) |
||
31 | ); |
||
32 | |||
33 | if (null !== $shared = $this->shared()) { |
||
|
|||
34 | $definition->setShared($shared); |
||
35 | } |
||
36 | |||
37 | foreach ($this->combinedAliases() as $alias) { |
||
38 | $container->add($alias, $id); |
||
39 | } |
||
40 | |||
41 | foreach ($this->combinedTags() as $tag) { |
||
42 | $definition->addTag($tag); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | protected function combinedAliases(): array |
||
47 | { |
||
48 | return [...$this->types(), ...$this->aliases()]; |
||
49 | } |
||
50 | |||
51 | protected function combinedTags(): array |
||
52 | { |
||
53 | return $this->tags(); |
||
54 | } |
||
55 | |||
56 | protected function shared(): ?bool |
||
57 | { |
||
58 | return true; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return array<string> |
||
63 | */ |
||
64 | protected function types(): array |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array<string> |
||
71 | */ |
||
72 | protected function aliases(): array |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return array<string> |
||
79 | */ |
||
80 | protected function tags(): array |
||
83 | } |
||
84 | |||
85 | abstract protected function service(ContainerInterface $container); |
||
86 | |||
87 | abstract protected function id(): string; |
||
88 | } |
||
89 |