|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiisoft\Di; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Container configuration. |
|
7
|
|
|
*/ |
|
8
|
|
|
final class ContainerConfig |
|
9
|
|
|
{ |
|
10
|
|
|
private array $providers = []; |
|
11
|
|
|
private array $tags = []; |
|
12
|
|
|
private bool $validate = true; |
|
13
|
|
|
private array $delegates = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param array $providers Service providers to get definitions from. |
|
17
|
|
|
* @return self |
|
18
|
|
|
*/ |
|
19
|
6 |
|
public function withProviders(array $providers): self |
|
20
|
|
|
{ |
|
21
|
6 |
|
$new = clone $this; |
|
22
|
6 |
|
$new->providers = $providers; |
|
23
|
6 |
|
return $new; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return array Service providers to get definitions from. |
|
28
|
|
|
*/ |
|
29
|
9 |
|
public function getProviders(): array |
|
30
|
|
|
{ |
|
31
|
9 |
|
return $this->providers; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array $tags Tagged service IDs. The structure is `['tagID' => ['service1', 'service2']]`. |
|
36
|
|
|
* @return self |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function withTags(array $tags): self |
|
39
|
|
|
{ |
|
40
|
2 |
|
$new = clone $this; |
|
41
|
2 |
|
$new->tags = $tags; |
|
42
|
2 |
|
return $new; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return array Tagged service IDs. The structure is `['tagID' => ['service1', 'service2']]`. |
|
47
|
|
|
*/ |
|
48
|
9 |
|
public function getTags(): array |
|
49
|
|
|
{ |
|
50
|
9 |
|
return $this->tags; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param bool $validate Whether definitions should be validated immediately. |
|
55
|
|
|
* @return self |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function withValidate(bool $validate): self |
|
58
|
|
|
{ |
|
59
|
1 |
|
$new = clone $this; |
|
60
|
1 |
|
$new->validate = $validate; |
|
61
|
1 |
|
return $new; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return bool Whether definitions should be validated immediately. |
|
66
|
|
|
*/ |
|
67
|
9 |
|
public function shouldValidate(): bool |
|
68
|
|
|
{ |
|
69
|
9 |
|
return $this->validate; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param array $delegates Container delegates. Each delegate is a callable in format |
|
74
|
|
|
* "function (ContainerInterface $container): ContainerInterface". The container instance returned is used |
|
75
|
|
|
* in case a service can not be found in primary container. |
|
76
|
|
|
* @return self |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function withDelegates(array $delegates): self |
|
79
|
|
|
{ |
|
80
|
1 |
|
$new = clone $this; |
|
81
|
1 |
|
$new->delegates = $delegates; |
|
82
|
1 |
|
return $new; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return array Container delegates. Each delegate is a callable in format |
|
87
|
|
|
* "function (ContainerInterface $container): ContainerInterface". The container instance returned is used |
|
88
|
|
|
* in case a service can not be found in primary container. |
|
89
|
|
|
*/ |
|
90
|
8 |
|
public function getDelegates(): array |
|
91
|
|
|
{ |
|
92
|
8 |
|
return $this->delegates; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|