1 | <?php |
||
14 | trait Injector |
||
15 | { |
||
16 | /** |
||
17 | * @var Container プロパティコンテナ |
||
18 | */ |
||
19 | private $__propertyContainer; |
||
20 | |||
21 | /** |
||
22 | * オブジェクトを注入する |
||
23 | * @param string プロパティ名 |
||
24 | * @param mixed オブジェクト |
||
25 | * @return Injector |
||
|
|||
26 | */ |
||
27 | 3 | public function inject(string $name, $object) |
|
33 | |||
34 | /** |
||
35 | * 型指定されたオブジェクトを注入する |
||
36 | * @param string プロパティ名 |
||
37 | * @param mixed オブジェクト |
||
38 | * @return Injector |
||
39 | */ |
||
40 | 5 | public function strictInject(string $name, $object) |
|
63 | |||
64 | /** |
||
65 | * overload setter |
||
66 | */ |
||
67 | public function __set($name, $value) |
||
74 | |||
75 | /** |
||
76 | * overload setter |
||
77 | */ |
||
78 | public function __get($name) |
||
82 | |||
83 | /** |
||
84 | * overload isset |
||
85 | */ |
||
86 | public function __isset($name) |
||
90 | |||
91 | /** |
||
92 | * overload unset |
||
93 | */ |
||
94 | public function __unset($name) |
||
98 | |||
99 | /** |
||
100 | * コンテナクリア |
||
101 | */ |
||
102 | public function __clear() |
||
106 | } |
||
107 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.