Total Complexity | 3 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class Hydrator |
||
14 | { |
||
15 | /** |
||
16 | * Class constructor |
||
17 | * |
||
18 | * @author Ronan Chilvers <[email protected]> |
||
19 | */ |
||
20 | 2 | public function __construct() |
|
22 | |||
23 | /** |
||
24 | * Hydrate a model from an array |
||
25 | * |
||
26 | * @param array $data |
||
27 | * @param \Ronanchilvers\Orm\Model $model |
||
28 | * @author Ronan Chilvers <[email protected]> |
||
29 | */ |
||
30 | 1 | public function hydrate(array $array, Model $model) |
|
31 | { |
||
32 | 1 | $closure = function($data) { |
|
33 | 1 | $this->data = $data; |
|
34 | 1 | $this->afterLoad(); |
|
35 | 1 | }; |
|
36 | 1 | $hydrator = $closure->bindTo($model, $model); |
|
37 | 1 | $hydrator($array); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Dehydrate a model to an array |
||
42 | * |
||
43 | * @param \Ronanchilvers\Orm\Model $model |
||
44 | * @return array |
||
45 | * @author Ronan Chilvers <[email protected]> |
||
46 | */ |
||
47 | 1 | public function dehydrate(Model $model) |
|
55 | } |
||
56 | } |
||
57 |