phpdoc
authorMichael Wallner <mike@php.net>
Mon, 21 Sep 2015 16:16:04 +0000 (18:16 +0200)
committerMichael Wallner <mike@php.net>
Mon, 21 Sep 2015 16:16:04 +0000 (18:16 +0200)
13 files changed:
lib/pq/Mapper/Map.php
lib/pq/Mapper/MapInterface.php
lib/pq/Mapper/Mapper.php
lib/pq/Mapper/ObjectManager.php
lib/pq/Mapper/Property.php
lib/pq/Mapper/Property/All.php
lib/pq/Mapper/Property/Field.php
lib/pq/Mapper/Property/Ref.php
lib/pq/Mapper/PropertyInterface.php
lib/pq/Mapper/RefProperty.php
lib/pq/Mapper/RefPropertyInterface.php
lib/pq/Mapper/Storage.php
lib/pq/Mapper/StorageInterface.php

index b63ba46213a95b1501956ef57ea68eff6b9b4611..58e1e5d5aa07c2f18208c59f066167e13dcb447f 100644 (file)
@@ -5,15 +5,37 @@ namespace pq\Mapper;
 use pq\Gateway\Row;
 use pq\Gateway\Rowset;
 use pq\Gateway\Table;
+use pq\Gateway\Table\Reference;
 use pq\Query\Expr;
 
 class Map implements MapInterface
 {
+       /**
+        * @var string
+        */
        private $class;
+
+       /**
+        * @var Table
+        */
        private $gateway;
+
+       /**
+        * @var ObjectManager
+        */
        private $objects;
+
+       /**
+        * @var PropertyInterface[]
+        */
        private $properties;
 
+       /**
+        * Create a new object map definition
+        * @param string $class
+        * @param Table $gateway
+        * @param ...PropertyInterface $properties
+        */
        function __construct($class, Table $gateway, PropertyInterface ...$properties) {
                $this->class = $class;
                $this->gateway = $gateway;
@@ -24,31 +46,56 @@ class Map implements MapInterface
                $this->objects = new ObjectManager($this);
        }
 
+       /**
+        * Get the name of the mapped class
+        * @return string
+        */
        function getClass() {
                return $this->class;
        }
 
+       /**
+        * Get the object manager
+        * @return ObjectManager
+        */
        function getObjects() {
                return $this->objects;
        }
 
        /**
+        * Get the underlying table gateway
         * @return Table
         */
        function getGateway() {
                return $this->gateway;
        }
 
+       /**
+        * Get the defined properties to map
+        * @return PropertyInterface[]
+        */
        function getProperties() {
                return $this->properties;
        }
 
+       /**
+        * Add a property to map
+        * @param PropertyInterface $property
+        * @return Map
+        */
        function addProperty(PropertyInterface $property) {
                $property->setContainer($this);
                $this->properties[] = $property;
                return $this;
        }
 
+       /**
+        * Get all child rows by foreign key
+        * @param Row $row
+        * @param string $refName
+        * @param array $objects
+        * @return Rowset
+        */
        function allOf(Row $row, $refName, &$objects = null) {
                /* apply objectOf to populate the object cache */
                return $this->gateway->of($row, $refName)->apply(function($row) use(&$objects) {
@@ -56,6 +103,13 @@ class Map implements MapInterface
                });
        }
 
+       /**
+        * Get the parent row by foreign key
+        * @param Row $row
+        * @param string $refName
+        * @param array $objects
+        * @return Rowset
+        */
        function refOf(Row $row, $refName, &$objects = null) {
                $rid = [];
                $rel = $row->getTable()->getRelation($this->gateway->getName(), $refName);
@@ -77,11 +131,22 @@ class Map implements MapInterface
                });
        }
 
+       /**
+        * Get the table relation reference
+        * @param MapInterface $map
+        * @param string $refName
+        * @return Reference
+        */
        function relOf(MapInterface $map, $refName) {
                return $map->getGateway()->getRelation(
                        $this->gateway->getName(), $refName);
        }
 
+       /**
+        * Drain the deferred callback queue
+        * @param callable[] $deferred
+        * @param callable $exec
+        */
        private function drain(array $deferred, callable $exec) {
                while ($deferred) {
                        $cb = array_shift($deferred);
@@ -91,6 +156,11 @@ class Map implements MapInterface
                }
        }
 
+       /**
+        * Map a row to an object
+        * @param Row $row
+        * @return object
+        */
        function map(Row $row) {
                $deferred = [];
                $object = $this->objects->asObject($row);
@@ -105,6 +175,11 @@ class Map implements MapInterface
                return $object;
        }
 
+       /**
+        * Map a rowset to an array of objects
+        * @param Rowset $rows
+        * @return object[]
+        */
        function mapAll(Rowset $rows) {
                $objects = [];
                foreach ($rows as $row) {
@@ -113,6 +188,10 @@ class Map implements MapInterface
                return $objects;
        }
 
+       /**
+        * Unmap on object
+        * @param object $object
+        */
        function unmap($object) {
                $deferred = [];
                /* @var $row Row */
@@ -149,5 +228,4 @@ class Map implements MapInterface
                        $row->update();
                }
        }
-
-}
\ No newline at end of file
+}
index 0e0db3a3e97e9c08e5e0c3326b388a6898fc7b3c..8c950568f365d82fb32b6af8ef5bdf3505dede82 100644 (file)
@@ -9,26 +9,31 @@ use pq\Gateway\Table;
 interface MapInterface
 {
        /**
+        * Get the mapped class' name
         * @return string
         */
        function getClass();
 
        /**
+        * The the underlying table gateway
         * @return Table
         */
        function getGateway();
 
        /**
-        * @return array of PropertyInterface instances
+        * Get the mapped properties
+        * @return PropertyInterface[]
         */
        function getProperties();
 
        /**
+        * Add a property to map
         * @param PropertyInterface $property
         */
        function addProperty(PropertyInterface $property);
 
        /**
+        * Get all child rows by foreign key
         * @param Row $row
         * @param string $refName
         * @param array $objects
@@ -37,6 +42,7 @@ interface MapInterface
        function allOf(Row $row, $refName, &$objects = null);
 
        /**
+        * Get the parent row by foreign key
         * @param Row $row
         * @param string $refName
         * @param array $objects
@@ -45,25 +51,29 @@ interface MapInterface
        function refOf(Row $row, $refName, &$objects = null);
 
        /**
+        * Get the table relation reference
         * @param MapInterface $map origin
         * @param string $refName relations reference name
-        * @return array relation reference
+        * @return Table\Reference
         */
        function relOf(MapInterface $map, $refName);
 
        /**
+        * Map a row to an object
         * @param Row $row
         * @return object
         */
        function map(Row $row);
 
        /**
+        * Map a rowset to an array of objects
         * @param Rowset $rows
-        * @return array
+        * @return object[]
         */
        function mapAll(Rowset $rows);
 
        /**
+        * Unmap on object
         * @param object $object
         * @return Row
         */
index 1c70f726fb81b0e477a8b683fb380a26cb726547..4a8f921e5888c426c9a74f824d6839b19d5f82e6 100644 (file)
@@ -2,37 +2,56 @@
 
 namespace pq\Mapper;
 
+use pq\Mapper\Property\All;
+use pq\Mapper\Property\Field;
+use pq\Mapper\Property\Ref;
+use ReflectionProperty;
 use UnexpectedValueException;
 
 class Mapper
 {
+       /**
+        * @var MapInterface[]
+        */
        private $maps;
+
+       /**
+        * @var ReflectionProperty[]
+        */
        private $refp;
 
        /**
-        * @param \pq\Mapper\MapInterface $map
-        * @return \pq\Mapper\Mapper
+        * Register a mapping
+        * @param MapInterface $map
+        * @return Mapper
         */
        function register(MapInterface $map) {
                $this->maps[$map->getClass()] = $map;
                return $this;
        }
 
+       /**
+        * Get a property reflector
+        * @param string $class
+        * @param string $prop
+        * @return ReflectionProperty
+        */
        function getReflector($class, $prop) {
                if (is_object($class)) {
                        $class = get_class($class);
                }
                $hash = "$class::$prop";
                if (!isset($this->refp[$hash])) {
-                       $this->refp[$hash] = new \ReflectionProperty($class, $prop);
+                       $this->refp[$hash] = new ReflectionProperty($class, $prop);
                        $this->refp[$hash]->setAccessible(true);
                }
                return $this->refp[$hash];
        }
 
        /**
+        * Get the mapping of $class
         * @param string $class
-        * @return \pq\Mapper\MapInterface
+        * @return MapInterface
         * @throws UnexpectedValueException
         */
        function mapOf($class) {
@@ -49,35 +68,39 @@ class Mapper
        }
 
        /**
+        * Create a storage for $class
         * @param string $class
-        * @return \pq\Mapper\Storage
+        * @return Storage
         */
        function createStorage($class) {
                return new Storage($this->mapOf($class));
        }
 
        /**
+        * Create a simple field mapping
         * @param string $property
         * @param string $field
-        * @return \pq\Mapper\Property\Field
+        * @return Field
         */
        function mapField($property, $field = null) {
-               return new Property\Field($this, $property, $field);
+               return new Field($this, $property, $field);
        }
 
        /**
+        * Create a child rows mapping by foreign key
         * @param string $property
-        * @return \pq\Mapper\Property\All
+        * @return All
         */
        function mapAll($property) {
-               return new Property\All($this, $property);
+               return new All($this, $property);
        }
 
        /**
+        * Create a parent row mapping by foreign key
         * @param string $property
-        * @return \pq\Mapper\Property\Ref
+        * @return Ref
         */
        function mapRef($property) {
-               return new Property\Ref($this, $property);
+               return new Ref($this, $property);
        }
 }
index 557d4943bddec0ab1cef2659f88111f60593160a..0281904c0bea60e94bee7068e44e5ddf9d75f6b9 100644 (file)
@@ -8,19 +8,47 @@ use pq\Gateway\Row;
 
 class ObjectManager
 {
+       /**
+        * @var MapInterface
+        */
        private $map;
+
+       /**
+        * @var object[]
+        */
        private $obj = [];
+
+       /**
+        * @var Row[]
+        */
        private $row = [];
 
+       /**
+        * Create a new ObjectManager for a mapping
+        * @param MapInterface $map
+        */
        function __construct(MapInterface $map) {
                $this->map = $map;
        }
 
+       /**
+        * Reset all managed objects
+        */
        function reset() {
                $this->obj = [];
                $this->row = [];
        }
 
+       /**
+        * Get the serialized row identity
+        *
+        * When $check is true, the identity will only be serialized if all columns
+        * of the primary key are set.
+        * 
+        * @param Row $row
+        * @param bool $check
+        * @return string|false serialized row id or false on failure
+        */
        function rowId(Row $row, $check = false) {
                try {
                        $identity = $row->getIdentity();
@@ -30,10 +58,20 @@ class ObjectManager
                return $this->serializeRowId($identity, $check);
        }
 
+       /**
+        * Get an object's identity
+        * @param object $object
+        * @return string
+        */
        function objectId($object) {
                return spl_object_hash($object);
        }
 
+       /**
+        * Extract a row's identity from a mapped object
+        * @param object $object
+        * @return string serialized row identity
+        */
        function extractRowId($object) {
                $id = [];
                foreach ($this->map->getGateway()->getIdentity() as $col) {
@@ -46,6 +84,12 @@ class ObjectManager
                return $this->serializeRowId($id, true);
        }
 
+       /**
+        * Serialize a row's identity
+        * @param mixed $identity
+        * @param bool $check
+        * @return string|false the serialized row identity or false on failure
+        */
        function serializeRowId($identity, $check = false) {
                if (is_scalar($identity)) {
                        return $identity;
@@ -65,10 +109,20 @@ class ObjectManager
                return json_encode($identity);
        }
 
+       /**
+        * Check whether a mapped object is already cached in the manager
+        * @param string $row_id
+        * @return bool
+        */
        function hasObject($row_id) {
                return isset($this->obj[$row_id]);
        }
 
+       /**
+        * Create a mapped object from $row
+        * @param Row $row
+        * @return object
+        */
        function createObject(Row $row) {
                $rid = $this->rowId($row);
                $cls = $this->map->getClass();
@@ -79,15 +133,30 @@ class ObjectManager
                return $obj;
        }
 
+       /**
+        * Forget the mapped object of $row
+        * @param Row $row
+        */
        function resetObject(Row $row) {
                unset($this->obj[$this->rowId($row)]);
        }
 
+       /**
+        * Get the mapped object of $row
+        * @param Row $row
+        * @return object
+        */
        function getObject(Row $row) {
                $id = $this->rowId($row);
                return $this->getObjectById($id);
        }
 
+       /**
+        * Get the mapped object of $row
+        * @param string $row_id
+        * @return object
+        * @throws BadMethodCallException
+        */
        function getObjectById($row_id) {
                if (!$this->hasObject($row_id)) {
                        throw new BadMethodCallException("Object of row with id $row_id does not exist");
@@ -95,16 +164,31 @@ class ObjectManager
                return $this->obj[$row_id];
        }
 
+       /**
+        * Check for a mapped object of $row, and create if necessary
+        * @param Row $row
+        * @return object
+        */
        function asObject(Row $row){
                return $this->hasObject($this->rowId($row))
                        ? $this->getObject($row)
                        : $this->createObject($row);
        }
 
+       /**
+        * Check whether a row for a mapped object exists
+        * @param string $obj_id
+        * @return Row
+        */
        function hasRow($obj_id) {
                return isset($this->row[$obj_id]);
        }
 
+       /**
+        * Initialize a Row from a mapped object
+        * @param object $object
+        * @return Row
+        */
        function createRow($object) {
                $oid = $this->objectId($object);
                $row = new Row($this->map->getGateway());
@@ -112,10 +196,20 @@ class ObjectManager
                return $row;
        }
 
+       /**
+        * Forget about a row of a mapped object
+        * @param object $object
+        */
        function resetRow($object) {
                unset($this->row [$this->objectId($object)]);
        }
-       
+
+       /**
+        * Get the row of a mapped object
+        * @param object $object
+        * @return Row
+        * @throws BadMethodCallException
+        */
        function getRow($object) {
                $id = $this->objectId($object);
 
@@ -125,9 +219,14 @@ class ObjectManager
                return $this->row[$id];
        }
 
+       /**
+        * Check for a row of a mapped object, create from object if neccessary
+        * @param object $object
+        * @return Row
+        */
        function asRow($object) {
                return $this->hasRow($this->objectId($object))
                        ? $this->getRow($object)
                        : $this->createRow($object);
        }
-}
\ No newline at end of file
+}
index ba4495bb39ed210224a11017ed3140eb2ef12f27..7d87ab3416a71ae7a71a6c4f5eb1d129d8d0415a 100644 (file)
@@ -4,43 +4,92 @@ namespace pq\Mapper;
 
 trait Property
 {
+       /**
+        *
+        * @var Mapper
+        */
        private $mapper;
+
+       /**
+        * @var string
+        */
        private $field;
+
+       /**
+        * @var string
+        */
        private $property;
 
+       /**
+        * Set the containing map
+        * @param MapInterface $container
+        * @return Property
+        */
        function setContainer(MapInterface $container) {
                $this->container = $container;
+               return $this;
        }
 
+       /**
+        * Get the containing map
+        * @return MapInterface
+        */
        function getContainer() {
                return $this->container;
        }
 
+       /**
+        * Get the property name
+        * @return string
+        */
        function getProperty() {
                return $this->property;
        }
 
+       /**
+        * Check whether this Property defines $property
+        * @param string $property
+        * @return bool
+        */
        function defines($property) {
                return $this->property === $property;
        }
 
+       /**
+        * Check whether this property exposes $field
+        * @param string $field
+        * @return bool
+        */
        function exposes($field) {
                return $this->field === $field;
        }
 
+       /**
+        * Set the value of the mapped property
+        * @param object $object
+        * @param mixed $value
+        */
        function assign($object, $value) {
                $this->mapper
                        ->getReflector($object, $this->property)
                        ->setValue($object, $value);
        }
 
+       /**
+        * Get the value of the mapped property
+        * @param object $object
+        * @return mixed
+        */
        function extract($object) {
                return $this->mapper
                        ->getReflector($object, $this->property)
                        ->getValue($object);
        }
 
+       /**
+        * @ignore
+        */
        function __toString() {
                return sprintf("%s: %s(%s)", get_class($this), $this->property, $this->field?:"NULL");
        }
-}
\ No newline at end of file
+}
index 0f45174a60bb8c2e3cfdbad82861c0dc2f6bf726..49fb0a622b4310a9ed410ee316362b62aeb6658c 100644 (file)
@@ -11,12 +11,22 @@ use UnexpectedValueException;
 class All implements RefPropertyInterface
 {
        use RefProperty;
-       
+
+       /**
+        * Create a child rows mapping
+        * @param Mapper $mapper
+        * @param string $property
+        */
        function __construct(Mapper $mapper, $property) {
                $this->mapper = $mapper;
                $this->property = $property;
        }
-       
+
+       /**
+        * Read the child objects
+        * @param Row $row
+        * @param object $objectToUpdate
+        */
        function read(Row $row, $objectToUpdate) {
                $val = $this->extract($objectToUpdate);
                if (!isset($val)) {
@@ -27,6 +37,12 @@ class All implements RefPropertyInterface
                }
        }
 
+       /**
+        * Write the child rows
+        * @param object $object
+        * @param Row $rowToUpdate
+        * @return callable deferred callback
+        */
        function write($object, Row $rowToUpdate) {
                $property = $this->findRefProperty($object);
                $map = $this->mapper->mapOf($this->refClass);
@@ -41,6 +57,12 @@ class All implements RefPropertyInterface
                };
        }
 
+       /**
+        * Find the referring property that references $object on our foreign key
+        * @param object $object
+        * @return RefPropertyInterface[]
+        * @throws UnexpectedValueException
+        */
        private function findRefProperty($object) {
                $map = $this->mapper->mapOf($this->refClass);
                $property = array_filter($map->getProperties(), function($property) use($object) {
@@ -57,4 +79,4 @@ class All implements RefPropertyInterface
                }
                return current($property);
        }
-}
\ No newline at end of file
+}
index 7a5774102f19c11f8859e7282915ff3e29f310cd..78c500bb02b18b208f34302ae9beac49a84db34b 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace pq\Mapper\Property;
 
+use pq\Gateway\Cell;
 use pq\Gateway\Row;
-
 use pq\Mapper\Mapper;
 use pq\Mapper\Property;
 use pq\Mapper\PropertyInterface;
@@ -12,18 +12,34 @@ class Field implements PropertyInterface
 {
        use Property;
 
+       /**
+        * Create a simple field mapping
+        * @param Mapper $mapper
+        * @param string $property
+        * @param string $field
+        */
        function __construct(Mapper $mapper, $property, $field = null) {
                $this->mapper = $mapper;
                $this->property = $property;
                $this->field = $field ?: $property;
        }
 
+       /**
+        * Read property value
+        * @param Row $row
+        * @param object $objectToUpdate
+        */
        function read(Row $row, $objectToUpdate) {
-               /* @var $val \pq\Gateway\Cell */
+               /* @var $val Cell */
                $val = $row->{$this->field};
                $this->assign($objectToUpdate, $val->get());
        }
 
+       /**
+        * Write property value
+        * @param object $object
+        * @param Row $rowToUpdate
+        */
        function write($object, Row $rowToUpdate) {
                $val = $this->extract($object);
                $rowToUpdate->{$this->field} = $val;
index 84f39f41e7cbd660969983967158b5aa862e1f59..01489d9c1b8180e201c37759dfd99b5981880a93 100644 (file)
@@ -4,6 +4,7 @@ namespace pq\Mapper\Property;
 
 use pq\Gateway\Row;
 use pq\Mapper\Mapper;
+use pq\Mapper\PropertyInterface;
 use pq\Mapper\RefProperty;
 use pq\Mapper\RefPropertyInterface;
 use UnexpectedValueException;
@@ -11,12 +12,22 @@ use UnexpectedValueException;
 class Ref implements RefPropertyInterface
 {
        use RefProperty;
-       
+
+       /**
+        * Create a parent row mapping
+        * @param Mapper $mapper
+        * @param string $property
+        */
        function __construct(Mapper $mapper, $property) {
                $this->mapper = $mapper;
                $this->property = $property;
        }
 
+       /**
+        * Read the parent object
+        * @param Row $row
+        * @param object $objectToUpdate
+        */
        function read(Row $row, $objectToUpdate) {
                $val = $this->extract($objectToUpdate);
                if (!isset($val)) {
@@ -27,6 +38,12 @@ class Ref implements RefPropertyInterface
                }
        }
 
+       /**
+        * Write the parent row's foreign key
+        * @param object $object
+        * @param Row $rowToUpdate
+        * @throws UnexpectedValueException
+        */
        function write($object, Row $rowToUpdate) {
                $map = $this->mapper->mapOf($this->refClass);
                $ref = $this->extract($object);
@@ -45,6 +62,11 @@ class Ref implements RefPropertyInterface
                }
        }
 
+       /**
+        * Find the property exposing $col
+        * @param string $col
+        * @return PropertyInterface[]
+        */
        private function findFieldProperty($col) {
                $map = $this->mapper->mapOf($this->refClass);
                return array_filter($map->getProperties(), function($property) use($col) {
index da6ccd32e9ddd4da6c90887fd33b25259367119a..b53e2b8976749737d1a33e8dc5e239bca9610c56 100644 (file)
@@ -6,18 +6,66 @@ use pq\Gateway\Row;
 
 interface PropertyInterface
 {
+       /**
+        * Write the value for the property from $object into the row to update
+        * @param object $object
+        * @param Row $rowToUpdate
+        * @return null|callable eventual deferred callback
+        */
        function write($object, Row $rowToUpdate);
+
+       /**
+        * Read the value for the property from $row into the mapped object
+        * @param Row $row
+        * @param object $objectToUpdate
+        * @return null|callable eventual deferred callback
+        */
        function read(Row $row, $objectToUpdate);
 
+       /**
+        * Set the value of the mapped property
+        * @param object $object
+        * @param mixed $value
+        */
        function assign($object, $value);
+
+       /**
+        * Get the value of the mapped property
+        * @param object $object
+        * @return mixed
+        */
        function extract($object);
        
+       /**
+        * Get the property name
+        * @return string
+        */
        function getProperty();
 
+       /**
+        * Get the containing map
+        * @return MapInterface
+        */
        function getContainer();
+
+       /**
+        * Set the containing map
+        * @param MapInterface $container
+        * @return Property
+        */
        function setContainer(MapInterface $container);
        
+       /**
+        * Check whether this Property defines $property
+        * @param string $property
+        * @return bool
+        */
        function defines($property);
-       function exposes($field);
 
+       /**
+        * Check whether this property exposes $field
+        * @param string $field
+        * @return bool
+        */
+       function exposes($field);
 }
index d7c6c6f6735cd485ecf4d4bcbe686de9a4e7482f..50b62883c5ab27bae0e7796b21bbf1e86d8f99f1 100644 (file)
@@ -6,25 +6,53 @@ trait RefProperty
 {
        use Property;
 
+       /**
+        * The referred class
+        * @var string
+        */
        private $refClass;
+
+       /**
+        * The foreign key name
+        * @var string
+        */
        private $refName;
 
+       /**
+        * Define the referred class
+        * @param string $class
+        * @return RefPropertyInterface
+        */
        function to($class) {
                $this->refClass = $class;
                return $this;
        }
 
+       /**
+        * Check whether this mapping refers to $class
+        * @param string $class
+        * @return bool
+        */
        function references($class) {
                return $this->refClass === (is_object($class) ? get_class($class) : $class);
        }
 
+       /**
+        * Define the foreign key name as defined by pq\Gateway\Table\Reference
+        * @param string $ref
+        * @return RefPropertyInterface
+        */
        function by($ref) {
                $this->refName = $ref;
                return $this;
        }
 
+       /**
+        * Check whether this mapping referes to a foreign key
+        * @param string $ref
+        * @return bool
+        */
        function on($ref) {
                return $this->refName === $ref;
        }
-
 }
index 5fae13ae20bf9613459e67f60ff2f77ad9beb353..f9b1ee5c3f03f76b766343b8d4f099cbfc78afe9 100644 (file)
@@ -5,22 +5,28 @@ namespace pq\Mapper;
 interface RefPropertyInterface extends PropertyInterface
 {
        /**
+        * Define the referred class
         * @param string $class
+        * @return RefPropertyInterface
         */
        function to($class);
 
        /**
+        * Check whether this mapping refers to $class
         * @param string $class
         * @return bool
         */
        function references($class);
 
        /**
+        * Define the foreign key name as defined by pq\Gateway\Table\Reference
         * @param string $ref
+        * @return RefPropertyInterface
         */
        function by($ref);
 
        /**
+        * Check whether this mapping referes to a foreign key
         * @param string $ref
         * @return bool
         */
index 8e0fcb4df7b20f8b8347e8e241e3c9626f180820..8016ef8b8cc13693ce368241f4c3f199d860ef6a 100644 (file)
@@ -2,39 +2,61 @@
 
 namespace pq\Mapper;
 
+use pq\Gateway\Table;
+
 class Storage implements StorageInterface
 {
        /**
-        *
-        * @var pq\Mapper\MapInterface
+        * The mapping of this storage
+        * @var MapInterface
         */
-       private $map;
+       var $map;
 
        /**
-        * @var \pq\Gateway\Table
+        * The underlying table gateway
+        * @var Table
         */
        private $gateway;
-       
+
+       /**
+        * Create a storage for $map
+        * @param MapInterface $map
+        */
        function __construct(MapInterface $map) {
                $this->map = $map;
                $this->gateway = $map->getGateway();
        }
-       
+
+       /**
+        * Find
+        * @param array $where
+        * @param string $order
+        * @param int $limit
+        * @param int $offset
+        * @return object[]
+        */
        function find($where = [], $order = null, $limit = null, $offset = null) {
                /* @var pq\Gateway\Rowset $rowset */
                $rowset = $this->gateway->find($where, $order, $limit, $offset);
                return $this->map->mapAll($rowset);
        }
-       
+
+       /**
+        * Delete
+        * @param object $object
+        */
        function delete($object) {
                $cache = $this->map->getObjects();
                $row = $cache->asRow($object)->delete();
                $cache->resetObject($row);
                $cache->resetRow($object);
        }
-       
+
+       /**
+        * Save
+        * @param object $object
+        */
        function save($object) {
                $this->map->unmap($object);
        }
-       
-}
\ No newline at end of file
+}
index 188318aa64d1f9816e309f2795e9135a23bb6f31..bb5c94a0f02207d9adf1172a5163eb86f5f6d4a1 100644 (file)
@@ -4,7 +4,25 @@ namespace pq\Mapper;
 
 interface StorageInterface
 {
-       function find($where, $order = null, $limit = null, $offset = null);
+       /**
+        * Find
+        * @param array $where
+        * @param string $order
+        * @param int $limit
+        * @param int $offset
+        * @return object[]
+        */
+       function find($where = [], $order = null, $limit = null, $offset = null);
+
+       /**
+        * Delete
+        * @param object $object
+        */
        function delete($object);
+
+       /**
+        * Save
+        * @param object $object
+        */
        function save($object);
 }