data mapper POC
[m6w6/pq-gateway] / lib / pq / Mapper / Property / Field.php
1 <?php
2
3 namespace pq\Mapper\Property;
4
5 use pq\Gateway\Row;
6
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 function __construct(Mapper $mapper, $property, $field = null) {
16 $this->mapper = $mapper;
17 $this->property = $property;
18 $this->field = $field ?: $property;
19 }
20
21 function read(Row $row, $objectToUpdate) {
22 /* @var $val \pq\Gateway\Cell */
23 $val = $row->{$this->field};
24 $this->assign($objectToUpdate, $val->get());
25 }
26
27 function write($object, Row $rowToUpdate) {
28 $val = $this->extract($object);
29 $rowToUpdate->{$this->field} = $val;
30 }
31 }