data mapper POC
[m6w6/pq-gateway] / lib / pq / Mapper / Property.php
diff --git a/lib/pq/Mapper/Property.php b/lib/pq/Mapper/Property.php
new file mode 100644 (file)
index 0000000..ba4495b
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace pq\Mapper;
+
+trait Property
+{
+       private $mapper;
+       private $field;
+       private $property;
+
+       function setContainer(MapInterface $container) {
+               $this->container = $container;
+       }
+
+       function getContainer() {
+               return $this->container;
+       }
+
+       function getProperty() {
+               return $this->property;
+       }
+
+       function defines($property) {
+               return $this->property === $property;
+       }
+
+       function exposes($field) {
+               return $this->field === $field;
+       }
+
+       function assign($object, $value) {
+               $this->mapper
+                       ->getReflector($object, $this->property)
+                       ->setValue($object, $value);
+       }
+
+       function extract($object) {
+               return $this->mapper
+                       ->getReflector($object, $this->property)
+                       ->getValue($object);
+       }
+
+       function __toString() {
+               return sprintf("%s: %s(%s)", get_class($this), $this->property, $this->field?:"NULL");
+       }
+}
\ No newline at end of file