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