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 | * |
||
56 | * @return object |
||
57 | */ |
||
58 | public function hydrateClass($class) |
||
72 | |||
73 | /** |
||
74 | * Hydrates property with value. |
||
75 | * Value can be anything. If the property is supposed to be a Class of anykind we will try to instantiate it |
||
76 | * and assign the class to the property |
||
77 | * |
||
78 | * @param $key |
||
79 | * @param $value |
||
80 | * @param \ReflectionClass $reflection |
||
81 | * |
||
82 | * @throws \Exception |
||
83 | */ |
||
84 | protected function hydrateProperty($key, $value, \ReflectionClass $reflection) |
||
112 | |||
113 | /** |
||
114 | * Resolves and returns propertyname |
||
115 | * |
||
116 | * @param $key |
||
117 | * |
||
118 | * @return mixed|string |
||
119 | */ |
||
120 | private function resolvePropertyName($key) |
||
131 | |||
132 | /** |
||
133 | * Checks if the value can be hydrated for iteration |
||
134 | * |
||
135 | * @param $value |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | private function isHydratableValue($value) |
||
143 | |||
144 | /** |
||
145 | * Checks if Classname resolved from docblock can be instantiated |
||
146 | * |
||
147 | * @param $className |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | private function isInstantiatable($className) |
||
155 | |||
156 | /** |
||
157 | * Checks (and fixes) objects against known errors |
||
158 | * |
||
159 | * @param Object &$object |
||
160 | * @param bool $fix Fix errors |
||
161 | * |
||
162 | * @return void |
||
163 | * |
||
164 | * @throws \Exception |
||
165 | */ |
||
166 | private function checkObjectForErrors(&$object, $fix = false) |
||
180 | } |