1 | <?php |
||
22 | final class Accessor implements AccessorInterface |
||
23 | { |
||
24 | private $buffer = []; |
||
25 | |||
26 | /** |
||
27 | * Assigns passed identifier to primary key |
||
28 | * Possible only when entity has one primary key |
||
29 | * |
||
30 | * @param ModelInterface $model |
||
31 | * @param mixed $entity |
||
32 | * @param int|string $identifier |
||
33 | * |
||
34 | * @return void |
||
35 | */ |
||
36 | public function identifyEntity(ModelInterface $model, &$entity, $identifier) |
||
47 | |||
48 | /** |
||
49 | * Returns property value |
||
50 | * |
||
51 | * @param array|object $entity |
||
52 | * @param string $field |
||
53 | * @param mixed $default |
||
54 | * |
||
55 | * @return mixed |
||
56 | * @throws AccessorException |
||
57 | */ |
||
58 | public function getPropertyValue($entity, $field, $default = null) |
||
73 | |||
74 | /** |
||
75 | * Sets property value |
||
76 | * |
||
77 | * @param array|object $entity |
||
78 | * @param string $field |
||
79 | * @param mixed $value |
||
80 | * |
||
81 | * @throws AccessorException |
||
82 | */ |
||
83 | public function setPropertyValue(&$entity, $field, $value) |
||
102 | |||
103 | /** |
||
104 | * Asserts if entity is array or object |
||
105 | * |
||
106 | * @param mixed $entity |
||
107 | * |
||
108 | * @throws AccessorException |
||
109 | */ |
||
110 | private function assertEntity($entity) |
||
116 | |||
117 | /** |
||
118 | * Returns object reflection instance |
||
119 | * |
||
120 | * @param object $object |
||
121 | * |
||
122 | * @return \ReflectionClass |
||
123 | */ |
||
124 | private function getReflection($object) |
||
134 | |||
135 | /** |
||
136 | * Returns object property instance |
||
137 | * |
||
138 | * @param \ReflectionClass $ref |
||
139 | * @param string $property |
||
140 | * |
||
141 | * @return \ReflectionProperty |
||
142 | */ |
||
143 | private function getProperty(\ReflectionClass $ref, $property) |
||
150 | |||
151 | /** |
||
152 | * Adds value to array property |
||
153 | * If property is not an array - will be converted into one preserving existing value as first element |
||
154 | * |
||
155 | * @param mixed $entity |
||
156 | * @param string $field |
||
157 | * @param mixed $value |
||
158 | * |
||
159 | * @throws AccessorException |
||
160 | */ |
||
161 | public function addPropertyValue(&$entity, $field, $value) |
||
172 | } |
||
173 |