phpdoc
[m6w6/pq-gateway] / lib / pq / Mapper / Property.php
1 <?php
2
3 namespace pq\Mapper;
4
5 trait Property
6 {
7 /**
8 *
9 * @var Mapper
10 */
11 private $mapper;
12
13 /**
14 * @var string
15 */
16 private $field;
17
18 /**
19 * @var string
20 */
21 private $property;
22
23 /**
24 * Set the containing map
25 * @param MapInterface $container
26 * @return Property
27 */
28 function setContainer(MapInterface $container) {
29 $this->container = $container;
30 return $this;
31 }
32
33 /**
34 * Get the containing map
35 * @return MapInterface
36 */
37 function getContainer() {
38 return $this->container;
39 }
40
41 /**
42 * Get the property name
43 * @return string
44 */
45 function getProperty() {
46 return $this->property;
47 }
48
49 /**
50 * Check whether this Property defines $property
51 * @param string $property
52 * @return bool
53 */
54 function defines($property) {
55 return $this->property === $property;
56 }
57
58 /**
59 * Check whether this property exposes $field
60 * @param string $field
61 * @return bool
62 */
63 function exposes($field) {
64 return $this->field === $field;
65 }
66
67 /**
68 * Set the value of the mapped property
69 * @param object $object
70 * @param mixed $value
71 */
72 function assign($object, $value) {
73 $this->mapper
74 ->getReflector($object, $this->property)
75 ->setValue($object, $value);
76 }
77
78 /**
79 * Get the value of the mapped property
80 * @param object $object
81 * @return mixed
82 */
83 function extract($object) {
84 return $this->mapper
85 ->getReflector($object, $this->property)
86 ->getValue($object);
87 }
88
89 /**
90 * @ignore
91 */
92 function __toString() {
93 return sprintf("%s: %s(%s)", get_class($this), $this->property, $this->field?:"NULL");
94 }
95 }