1 | <?php |
||
31 | trait FactoryHelperTrait |
||
32 | { |
||
33 | /** |
||
34 | * Get service definition |
||
35 | * |
||
36 | * @param string $rawId |
||
37 | * @param array $args |
||
38 | * @return array |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected function getDefinition( |
||
60 | |||
61 | /** |
||
62 | * Instantiate service object from classname |
||
63 | * |
||
64 | * @param string $class |
||
65 | * @param array $args |
||
66 | * @return object |
||
67 | * @throws LogicException if something goes wrong |
||
68 | * @access protected |
||
69 | */ |
||
70 | protected function constructObject(/*# string */ $class, array $args) |
||
87 | |||
88 | /** |
||
89 | * Match provided arguments with a method/function's reflection parameters |
||
90 | * |
||
91 | * @param \ReflectionParameter[] $reflectionParameters |
||
92 | * @param array $providedArguments |
||
93 | * @return array the resolved arguments |
||
94 | * @throws LogicException |
||
95 | * @access protected |
||
96 | */ |
||
97 | protected function matchArguments( |
||
115 | |||
116 | /** |
||
117 | * Try best to guess parameter and argument are the same type |
||
118 | * |
||
119 | * @param null|\ReflectionClass $class |
||
120 | * @param array $arguments |
||
121 | * @return bool |
||
122 | * @access protected |
||
123 | */ |
||
124 | protected function isTypeMatched($class, array $arguments)/*# : bool */ |
||
134 | |||
135 | /** |
||
136 | * Is $param required and is a class/interface |
||
137 | * |
||
138 | * @param \ReflectionParameter $param |
||
139 | * @param array $arguments |
||
140 | * @return bool |
||
141 | * @throws LogicException if mismatched arguments |
||
142 | * @access protected |
||
143 | */ |
||
144 | protected function isRequiredClass( |
||
155 | |||
156 | /** |
||
157 | * Get an object base on provided classname or interface name |
||
158 | * |
||
159 | * @param string $classname class or interface name |
||
160 | * @return object |
||
161 | * @throws \Exception if something goes wrong |
||
162 | * @access protected |
||
163 | */ |
||
164 | protected function getObjectByClass(/*# string */ $classname) |
||
176 | |||
177 | /** |
||
178 | * Get callable parameters |
||
179 | * |
||
180 | * @param callable $callable |
||
181 | * @return \ReflectionParameter[] |
||
182 | * @throws LogicException if something goes wrong |
||
183 | * @access protected |
||
184 | */ |
||
185 | protected function getCallableParameters(callable $callable)/*# : array */ |
||
204 | |||
205 | /** |
||
206 | * Is $var a non-closure object with '__invoke()' defined ? |
||
207 | * |
||
208 | * @param mixed $var |
||
209 | * @return bool |
||
210 | * @access protected |
||
211 | */ |
||
212 | protected function isInvocable($var)/*# : bool */ |
||
218 | } |
||
219 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.