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