storage test
[m6w6/pq-gateway] / lib / pq / Mapper / Property / Field.php
1 <?php
2
3 namespace pq\Mapper\Property;
4
5 use pq\Gateway\Cell;
6 use pq\Gateway\Row;
7 use pq\Mapper\Mapper;
8 use pq\Mapper\Property;
9 use pq\Mapper\PropertyInterface;
10
11 class Field implements PropertyInterface
12 {
13 use Property;
14
15 /**
16 * Create a simple field mapping
17 * @param Mapper $mapper
18 * @param string $property
19 * @param string $field
20 */
21 function __construct(Mapper $mapper, $property, $field = null) {
22 $this->mapper = $mapper;
23 $this->property = $property;
24 $this->field = $field ?: $property;
25 }
26
27 /**
28 * Read property value
29 * @param Row $row
30 * @param object $objectToUpdate
31 */
32 function read(Row $row, $objectToUpdate) {
33 /* @var $val Cell */
34 $val = $row->{$this->field};
35 $this->assign($objectToUpdate, $val->get());
36 }
37
38 /**
39 * Write property value
40 * @param object $object
41 * @param Row $rowToUpdate
42 */
43 function write($object, Row $rowToUpdate) {
44 $val = $this->extract($object);
45 $rowToUpdate->{$this->field} = $val;
46 }
47 }