1 | <?php |
||
29 | trait FactoryHelperTrait |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * Instantiate service object from classname |
||
34 | * |
||
35 | * @param string $class |
||
36 | * @param array $args |
||
37 | * @return object |
||
38 | * @throws LogicException if something goes wrong |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected function constructObject(/*# string */ $class, array $args) |
||
58 | |||
59 | /** |
||
60 | * Match provided arguments with a method/function's reflection parameters |
||
61 | * |
||
62 | * @param \ReflectionParameter[] $reflectionParameters |
||
63 | * @param array $providedArguments |
||
64 | * @return array the resolved arguments |
||
65 | * @throws LogicException |
||
66 | * @access protected |
||
67 | */ |
||
68 | protected function matchArguments( |
||
86 | |||
87 | /** |
||
88 | * Try best to guess parameter and argument are the same type |
||
89 | * |
||
90 | * @param null|\ReflectionClass $class |
||
91 | * @param array $arguments |
||
92 | * @return bool |
||
93 | * @access protected |
||
94 | */ |
||
95 | protected function isTypeMatched($class, array $arguments)/*# : bool */ |
||
105 | |||
106 | /** |
||
107 | * Is $param required and is a class/interface |
||
108 | * |
||
109 | * @param \ReflectionParameter $param |
||
110 | * @param array $arguments |
||
111 | * @return bool |
||
112 | * @throws LogicException if mismatched arguments |
||
113 | * @access protected |
||
114 | */ |
||
115 | protected function isRequiredClass( |
||
126 | |||
127 | /** |
||
128 | * Get callable parameters |
||
129 | * |
||
130 | * @param callable $callable |
||
131 | * @return \ReflectionParameter[] |
||
132 | * @throws LogicException if something goes wrong |
||
133 | * @access protected |
||
134 | */ |
||
135 | protected function getCallableParameters(callable $callable)/*# : array */ |
||
154 | |||
155 | /** |
||
156 | * Is $var a non-closure object with '__invoke()' defined ? |
||
157 | * |
||
158 | * @param mixed $var |
||
159 | * @return bool |
||
160 | * @access protected |
||
161 | */ |
||
162 | protected function isInvocable($var)/*# : bool */ |
||
168 | } |
||
169 |
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.