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