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
|
|
|
private bool $useStrictMode = false; |
18
|
|
|
|
19
|
98 |
|
private function __construct() |
20
|
|
|
{ |
21
|
98 |
|
} |
22
|
|
|
|
23
|
98 |
|
public static function create(): self |
24
|
|
|
{ |
25
|
98 |
|
return new self(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param array $definitions Definitions to put into container. |
30
|
|
|
* |
31
|
|
|
* @return self |
32
|
|
|
*/ |
33
|
89 |
|
public function withDefinitions(array $definitions): self |
34
|
|
|
{ |
35
|
89 |
|
$new = clone $this; |
36
|
89 |
|
$new->definitions = $definitions; |
37
|
89 |
|
return $new; |
38
|
|
|
} |
39
|
|
|
|
40
|
98 |
|
public function getDefinitions(): array |
41
|
|
|
{ |
42
|
98 |
|
return $this->definitions; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param array $providers Service providers to get definitions from. |
47
|
|
|
* |
48
|
|
|
* @return self |
49
|
|
|
*/ |
50
|
6 |
|
public function withProviders(array $providers): self |
51
|
|
|
{ |
52
|
6 |
|
$new = clone $this; |
53
|
6 |
|
$new->providers = $providers; |
54
|
6 |
|
return $new; |
55
|
|
|
} |
56
|
|
|
|
57
|
92 |
|
public function getProviders(): array |
58
|
|
|
{ |
59
|
92 |
|
return $this->providers; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param array $tags Tagged service IDs. The structure is `['tagID' => ['service1', 'service2']]`. |
64
|
|
|
* |
65
|
|
|
* @return self |
66
|
|
|
*/ |
67
|
2 |
|
public function withTags(array $tags): self |
68
|
|
|
{ |
69
|
2 |
|
$new = clone $this; |
70
|
2 |
|
$new->tags = $tags; |
71
|
2 |
|
return $new; |
72
|
|
|
} |
73
|
|
|
|
74
|
98 |
|
public function getTags(): array |
75
|
|
|
{ |
76
|
98 |
|
return $this->tags; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param bool $validate Whether definitions should be validated immediately. |
81
|
|
|
* |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
1 |
|
public function withValidate(bool $validate): self |
85
|
|
|
{ |
86
|
1 |
|
$new = clone $this; |
87
|
1 |
|
$new->validate = $validate; |
88
|
1 |
|
return $new; |
89
|
|
|
} |
90
|
|
|
|
91
|
98 |
|
public function shouldValidate(): bool |
92
|
|
|
{ |
93
|
98 |
|
return $this->validate; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param array $delegates Container delegates. Each delegate is a callable in format |
98
|
|
|
* `function (ContainerInterface $container): ContainerInterface`. The container instance returned is used |
99
|
|
|
* in case a service can not be found in primary container. |
100
|
|
|
* |
101
|
|
|
* @return self |
102
|
|
|
*/ |
103
|
1 |
|
public function withDelegates(array $delegates): self |
104
|
|
|
{ |
105
|
1 |
|
$new = clone $this; |
106
|
1 |
|
$new->delegates = $delegates; |
107
|
1 |
|
return $new; |
108
|
|
|
} |
109
|
|
|
|
110
|
91 |
|
public function getDelegates(): array |
111
|
|
|
{ |
112
|
91 |
|
return $this->delegates; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param bool $useStrictMode If the automatic addition of definition when class exists and can be resolved |
117
|
|
|
* is disabled. |
118
|
|
|
* |
119
|
|
|
* @return self |
120
|
|
|
*/ |
121
|
2 |
|
public function withStrictMode(bool $useStrictMode): self |
122
|
|
|
{ |
123
|
2 |
|
$new = clone $this; |
124
|
2 |
|
$new->useStrictMode = $useStrictMode; |
125
|
2 |
|
return $new; |
126
|
|
|
} |
127
|
|
|
|
128
|
98 |
|
public function useStrictMode(): bool |
129
|
|
|
{ |
130
|
98 |
|
return $this->useStrictMode; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|