data mapper POC
[m6w6/pq-gateway] / lib / pq / Mapper / Property.php
1 <?php
2
3 namespace pq\Mapper;
4
5 trait Property
6 {
7 private $mapper;
8 private $field;
9 private $property;
10
11 function setContainer(MapInterface $container) {
12 $this->container = $container;
13 }
14
15 function getContainer() {
16 return $this->container;
17 }
18
19 function getProperty() {
20 return $this->property;
21 }
22
23 function defines($property) {
24 return $this->property === $property;
25 }
26
27 function exposes($field) {
28 return $this->field === $field;
29 }
30
31 function assign($object, $value) {
32 $this->mapper
33 ->getReflector($object, $this->property)
34 ->setValue($object, $value);
35 }
36
37 function extract($object) {
38 return $this->mapper
39 ->getReflector($object, $this->property)
40 ->getValue($object);
41 }
42
43 function __toString() {
44 return sprintf("%s: %s(%s)", get_class($this), $this->property, $this->field?:"NULL");
45 }
46 }