1 | <?php |
||
23 | trait ContainerTrait |
||
24 | { |
||
25 | use ResolveTrait; |
||
26 | use FactoryTrait; |
||
27 | use ConfigAwareTrait; |
||
28 | |||
29 | /** |
||
30 | * service objects stored by its service id |
||
31 | * |
||
32 | * @var object[] |
||
33 | */ |
||
34 | protected $objects = []; |
||
35 | |||
36 | /** |
||
37 | * DI definition prefix in $config |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $prefix = 'di.'; |
||
42 | |||
43 | /** |
||
44 | * Get the instance by id, create it if not yet |
||
45 | * |
||
46 | * @param string $id |
||
47 | * @return object |
||
48 | * @throws UnresolvedClassException |
||
49 | * @throws LogicException |
||
50 | */ |
||
51 | protected function getInstance(string $id): object |
||
76 | |||
77 | /** |
||
78 | * create a new instance by its definition |
||
79 | * |
||
80 | * @param array $definition |
||
81 | * @return object |
||
82 | * @throws UnresolvedClassException |
||
83 | * @throws LogicException |
||
84 | */ |
||
85 | protected function newInstance(array $definition): object |
||
93 | |||
94 | /** |
||
95 | * get the raw service id with the scope '@XXX' cut-off |
||
96 | * |
||
97 | * @param string $id |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function getRawId(string $id): string |
||
105 | |||
106 | /** |
||
107 | * execute 'di.before' or 'di.after' methods for newly created object |
||
108 | * |
||
109 | * @param object|array $object newly created object or object definition |
||
110 | * @param string $stage 'before' | 'after' |
||
111 | * @return void |
||
112 | * @throws LogicException |
||
113 | */ |
||
114 | protected function executeMethods($object, string $stage): void |
||
124 | |||
125 | /** |
||
126 | * Find a service in the definitions |
||
127 | * |
||
128 | * @param string $id |
||
129 | * @return bool |
||
130 | */ |
||
131 | protected function hasDefinition(string $id): bool |
||
135 | |||
136 | /** |
||
137 | * @param string $id |
||
138 | * @return array |
||
139 | */ |
||
140 | protected function getServiceDefinition(string $id): array |
||
145 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.