1 | <?php |
||
21 | trait HydratableTrait |
||
22 | { |
||
23 | use PropertyTrait; |
||
24 | use ReflectionTrait; |
||
25 | |||
26 | /** |
||
27 | * List of types which are not used as objects |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | public static $nonObjectTypes = ['string', 'int', 'integer', 'bool', 'boolean', 'array', 'float', 'mixed', 'null']; |
||
32 | |||
33 | /** |
||
34 | * List of classes which will take string arguments in constructor |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $giveDataInConstructor = ['\DateTime']; |
||
39 | |||
40 | /** |
||
41 | * Object constructor arguments to be passed when creating an object during conversion |
||
42 | * |
||
43 | * @var mixed |
||
44 | */ |
||
45 | protected $objectConstructorArguments; |
||
46 | |||
47 | /** |
||
48 | * Converts a stdClass to models loaded in current context |
||
49 | * |
||
50 | * This method iterates over the passed $class |
||
51 | * For each key, it looks for a setter and type. |
||
52 | * If the value is an object, it initializes the object and assignes the initialized object. |
||
53 | * |
||
54 | * @param object|array $class class |
||
55 | * @param boolean $failOnError Throw Exception if any error(s) occur |
||
56 | * |
||
57 | * @return object |
||
58 | * |
||
59 | * @throws \Exception if hydration failes AND $failOnError is true |
||
60 | */ |
||
61 | 4 | public function hydrateClass($class, $failOnError = false) |
|
79 | |||
80 | /** |
||
81 | * Hydrates property with value. |
||
82 | * Value can be anything. If the property is supposed to be a Class of anykind we will try to instantiate it |
||
83 | * and assign the class to the property |
||
84 | * |
||
85 | * @param $key |
||
86 | * @param $value |
||
87 | * @param \ReflectionClass $reflection |
||
88 | * |
||
89 | * @throws \Exception |
||
90 | */ |
||
91 | 4 | protected function hydrateProperty($key, $value, \ReflectionClass $reflection) |
|
118 | |||
119 | /** |
||
120 | * Resolves and returns propertyname |
||
121 | * |
||
122 | * @param $key |
||
123 | * |
||
124 | * @return mixed|string |
||
125 | */ |
||
126 | 4 | private function resolvePropertyName($key) |
|
137 | |||
138 | /** |
||
139 | * Checks if the value can be hydrated for iteration |
||
140 | * |
||
141 | * @param $value |
||
142 | * |
||
143 | * @return bool |
||
144 | */ |
||
145 | 4 | private function isHydratableValue($value) |
|
149 | |||
150 | /** |
||
151 | * Checks (and fixes) objects against known errors |
||
152 | * |
||
153 | * @param Object &$object |
||
154 | * @param bool $fix Fix errors |
||
155 | * |
||
156 | * @return void |
||
157 | * |
||
158 | * @throws \Exception |
||
159 | */ |
||
160 | 4 | private function checkObjectForErrors(&$object, $fix = false) |
|
168 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.