|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Collector; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
|
8
|
|
|
|
|
9
|
|
|
use function in_array; |
|
10
|
|
|
use function is_callable; |
|
11
|
|
|
|
|
12
|
|
|
final class ContainerProxyConfig |
|
13
|
|
|
{ |
|
14
|
|
|
private int $logLevel; |
|
15
|
|
|
|
|
16
|
|
|
private array $decoratedServices; |
|
17
|
|
|
|
|
18
|
|
|
private bool $active; |
|
19
|
|
|
|
|
20
|
|
|
private ?EventDispatcherInterface $dispatcher; |
|
21
|
|
|
|
|
22
|
|
|
private ?ServiceCollector $collector; |
|
23
|
|
|
|
|
24
|
|
|
private ?string $proxyCachePath; |
|
25
|
|
|
|
|
26
|
11 |
|
public function __construct( |
|
27
|
|
|
bool $active = false, |
|
28
|
|
|
array $decoratedServices = [], |
|
29
|
|
|
EventDispatcherInterface $dispatcher = null, |
|
30
|
|
|
ServiceCollector $collector = null, |
|
31
|
|
|
string $proxyCachePath = null, |
|
32
|
|
|
int $logLevel = 0 |
|
33
|
|
|
) { |
|
34
|
11 |
|
$this->active = $active; |
|
35
|
11 |
|
$this->decoratedServices = $decoratedServices; |
|
36
|
11 |
|
$this->dispatcher = $dispatcher; |
|
37
|
11 |
|
$this->collector = $collector; |
|
38
|
11 |
|
$this->proxyCachePath = $proxyCachePath; |
|
39
|
11 |
|
$this->logLevel = $logLevel; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function activate(): self |
|
43
|
|
|
{ |
|
44
|
1 |
|
$config = clone $this; |
|
45
|
1 |
|
$config->active = true; |
|
46
|
|
|
|
|
47
|
1 |
|
return $config; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function withDispatcher(EventDispatcherInterface $dispatcher): self |
|
51
|
|
|
{ |
|
52
|
1 |
|
$config = clone $this; |
|
53
|
1 |
|
$config->dispatcher = $dispatcher; |
|
54
|
|
|
|
|
55
|
1 |
|
return $config; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function withLogLevel(int $logLevel): self |
|
59
|
|
|
{ |
|
60
|
1 |
|
$config = clone $this; |
|
61
|
1 |
|
$config->logLevel = $logLevel; |
|
62
|
|
|
|
|
63
|
1 |
|
return $config; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function withProxyCachePath(string $proxyCachePath): self |
|
67
|
|
|
{ |
|
68
|
1 |
|
$config = clone $this; |
|
69
|
1 |
|
$config->proxyCachePath = $proxyCachePath; |
|
70
|
|
|
|
|
71
|
1 |
|
return $config; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
public function withCollector(ServiceCollector $collector): self |
|
75
|
|
|
{ |
|
76
|
1 |
|
$config = clone $this; |
|
77
|
1 |
|
$config->collector = $collector; |
|
78
|
|
|
|
|
79
|
1 |
|
return $config; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
2 |
|
public function withDecoratedServices(array $decoratedServices): self |
|
83
|
|
|
{ |
|
84
|
2 |
|
$config = clone $this; |
|
85
|
2 |
|
$config->decoratedServices = array_merge($this->decoratedServices, $decoratedServices); |
|
86
|
|
|
|
|
87
|
2 |
|
return $config; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
6 |
|
public function getIsActive(): bool |
|
91
|
|
|
{ |
|
92
|
6 |
|
return $this->active; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
7 |
|
public function getLogLevel(): int |
|
96
|
|
|
{ |
|
97
|
7 |
|
return $this->logLevel; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
6 |
|
public function getDecoratedServices(): array |
|
101
|
|
|
{ |
|
102
|
6 |
|
return $this->decoratedServices; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
7 |
|
public function getDispatcher(): ?EventDispatcherInterface |
|
106
|
|
|
{ |
|
107
|
7 |
|
return $this->dispatcher; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
7 |
|
public function getCollector(): ?ServiceCollector |
|
111
|
|
|
{ |
|
112
|
7 |
|
return $this->collector; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
8 |
|
public function getProxyCachePath(): ?string |
|
116
|
|
|
{ |
|
117
|
8 |
|
return $this->proxyCachePath; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
4 |
|
public function getDecoratedServiceConfig($service) |
|
121
|
|
|
{ |
|
122
|
4 |
|
return $this->decoratedServices[$service]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
6 |
|
public function hasDecoratedService(string $service): bool |
|
126
|
|
|
{ |
|
127
|
6 |
|
return isset($this->decoratedServices[$service]) || in_array($service, $this->decoratedServices, true); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
4 |
|
public function hasDecoratedServiceArrayConfigWithStringKeys(string $service): bool |
|
131
|
|
|
{ |
|
132
|
4 |
|
return $this->hasDecoratedServiceArrayConfig($service) && !isset($this->decoratedServices[$service][0]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
4 |
|
public function hasDecoratedServiceArrayConfig(string $service): bool |
|
136
|
|
|
{ |
|
137
|
4 |
|
return isset($this->decoratedServices[$service]) && is_array($this->decoratedServices[$service]); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
5 |
|
public function hasDecoratedServiceCallableConfig(string $service): bool |
|
141
|
|
|
{ |
|
142
|
5 |
|
return isset($this->decoratedServices[$service]) && is_callable($this->decoratedServices[$service]); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
1 |
|
public function hasDispatcher(): bool |
|
146
|
|
|
{ |
|
147
|
1 |
|
return $this->dispatcher !== null; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
2 |
|
public function hasCollector(): bool |
|
151
|
|
|
{ |
|
152
|
2 |
|
return $this->collector !== null; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|