@@ 33-48 (lines=16) @@ | ||
30 | * @param string $field |
|
31 | * @return mixed |
|
32 | */ |
|
33 | public function get($object, string $field) |
|
34 | { |
|
35 | if (is_array($object)) { |
|
36 | return $this->getFromArray($object, $field); |
|
37 | } |
|
38 | ||
39 | if (is_object($object)) { |
|
40 | return $this->getFromObject($object, $field); |
|
41 | } |
|
42 | ||
43 | if ($this->throwOnFail) { |
|
44 | throw new ReflectionException("cannot extract field '$field' from non-object, non-array value"); |
|
45 | } else { |
|
46 | return null; |
|
47 | } |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * @param $object |
@@ 33-48 (lines=16) @@ | ||
30 | * @param string $field |
|
31 | * @param mixed $value |
|
32 | */ |
|
33 | public function set(&$object, string $field, $value) |
|
34 | { |
|
35 | if (is_array($object)) { |
|
36 | $this->setInArray($object, $field, $value); |
|
37 | return; |
|
38 | } |
|
39 | ||
40 | if (is_object($object)) { |
|
41 | $this->setInObject($object, $field, $value); |
|
42 | return; |
|
43 | } |
|
44 | ||
45 | if ($this->throwOnFail) { |
|
46 | throw new ReflectionException("cannot set field '$field' in non-object, non-array value"); |
|
47 | } |
|
48 | } |
|
49 | ||
50 | protected function setInArray(&$object, string $field, $value) |
|
51 | { |