| Conditions | 8 |
| Paths | 6 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public static function populateArrayFromObject(array $params, $model, array $data = []) |
||
| 18 | { |
||
| 19 | |||
| 20 | $return = []; |
||
| 21 | foreach ($params as $name) { |
||
| 22 | if (isset($data[$name])) { |
||
| 23 | $return[$name] = $data[$name]; |
||
| 24 | continue; |
||
| 25 | } |
||
| 26 | $root = $model; |
||
| 27 | // Split the name on -> so we can set URL parts from relationships. |
||
| 28 | $exploded = explode('->', $name); |
||
| 29 | // Remove the last one, this is the attribute we actually want to get. |
||
| 30 | $last = array_pop($exploded); |
||
| 31 | // Change the $root to be whatever relationship in necessary. |
||
| 32 | foreach ($exploded as $part) { |
||
| 33 | $root = $root->$part; |
||
| 34 | } |
||
| 35 | |||
| 36 | if ($last && (property_exists($root, $last) || (method_exists($root, '__get') && $root->$last))) { |
||
| 37 | // Get the value. |
||
| 38 | $return[$name] = $root->$last; |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | |||
| 42 | $return[$name] = null; |
||
| 43 | } |
||
| 44 | |||
| 45 | return $return; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |