[+TASK] Extbase (DomainObject): Added a "private" property _localizationParentUid...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / LazyLoadingProxy.php
index 8d393c9..bb20883 100644 (file)
  *
  * @package Extbase
  * @subpackage Persistence
- * @version $Id: LazyLoadingProxy.php 2591 2009-06-09 19:23:47Z k-fish $
+ * @version $Id$
  */
-// TODO Implement support for CountableInterface
-class Tx_Extbase_Persistence_LazyLoadingProxy {
-
-       /**
-        * @var Tx_Extbase_Persistence_QueryFactoryInterface
-        */
-       protected $queryFactory;
+class Tx_Extbase_Persistence_LazyLoadingProxy implements Iterator, Tx_Extbase_Persistence_LoadingStrategyInterface {
 
        /**
         * The object this property is contained in.
@@ -61,42 +55,39 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         * @var mixed
         */
        private $fieldValue;
-
-       /**
-        *
-        * @var Tx_Extbase_Persistence_Mapper_ColumnMap
-        */
-       private $columnMap;
-
+       
        /**
         * Constructs this proxy instance.
         *
         * @param object $parentObject The object instance this proxy is part of
         * @param string $propertyName The name of the proxied property in it's parent
         * @param mixed $fieldValue The raw field value.
-        * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The corresponding Data Map of the property
-
         */
-       public function __construct($parentObject, $propertyName, $fieldValue, Tx_Extbase_Persistence_Mapper_ColumnMap $columnMap) {
-               $this->queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
+       public function __construct($parentObject, $propertyName, $fieldValue) {
                $this->parentObject = $parentObject;
                $this->propertyName = $propertyName;
                $this->fieldValue = $fieldValue;
-               $this->columnMap = $columnMap;
        }
 
        /**
         * Populate this proxy by asking the $population closure.
         *
         * @return object The instance (hopefully) returned
-
         */
        public function _loadRealInstance() {
-               $dataMapper = Tx_Extbase_Dispatcher::getPersistenceManager()->getBackend()->getDataMapper();
-               $result = $dataMapper->fetchRelatedObjects($this->parentObject, $this->propertyName, $this->fieldValue, $this->columnMap);
-               $this->parentObject->_setProperty($this->propertyName, $result);
-               $this->parentObject->_memorizeCleanState($this->propertyName);
-               return $result;
+               // this check safeguards against a proxy being activated multiple times
+               // usually that does not happen, but if the proxy is held from outside
+               // it's parent... the result would be weird.
+               if ($this->parentObject->_getProperty($this->propertyName) instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
+                       $dataMapper = Tx_Extbase_Dispatcher::getPersistenceManager()->getBackend()->getDataMapper();
+                       $objects = $dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE, FALSE);
+                       $propertyValue = $dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
+                       $this->parentObject->_setProperty($this->propertyName, $propertyValue);
+                       $this->parentObject->_memorizeCleanState($this->propertyName);
+                       return $propertyValue;
+               } else {
+                       return $this->parentObject->_getProperty($this->propertyName);
+               }
        }
 
        /**
@@ -105,7 +96,6 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         * @param string $methodName The name of the property to get
         * @param array $arguments The arguments given to the call
         * @return mixed
-
         */
        public function __call($methodName, $arguments) {
                $realInstance = $this->_loadRealInstance();
@@ -117,7 +107,6 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         *
         * @param string $propertyName The name of the property to get
         * @return mixed
-
         */
        public function __get($propertyName) {
                $realInstance = $this->_loadRealInstance();
@@ -130,7 +119,6 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         * @param string $propertyName The name of the property to set
         * @param mixed $value The value for the property to set
         * @return void
-
         */
        public function __set($propertyName, $value) {
                $realInstance = $this->_loadRealInstance();
@@ -142,7 +130,6 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         *
         * @param string $propertyName The name of the property to check
         * @return boolean
-
         */
        public function __isset($propertyName) {
                $realInstance = $this->_loadRealInstance();
@@ -154,11 +141,62 @@ class Tx_Extbase_Persistence_LazyLoadingProxy {
         *
         * @param string $propertyName The name of the property to unset
         * @return void
-
         */
        public function __unset($propertyName) {
                $realInstance = $this->_loadRealInstance();
                unset($realInstance->$propertyName);
        }
+       
+       /**
+        * Returns the current value of the storage array
+        *
+        * @return void
+        */
+       public function current() {
+               $realInstance = $this->_loadRealInstance();
+               return current($realInstance);
+       }
+
+       /**
+        * Returns the current key storage array
+        *
+        * @return void
+        */
+       public function key() {
+               $realInstance = $this->_loadRealInstance();
+               return key($realInstance);
+       }
+
+       /**
+        * Returns the next position of the storage array
+        *
+        * @return void
+        */
+       public function next() {
+               $realInstance = $this->_loadRealInstance();
+               next($realInstance);
+       }
+       
+       /**
+        * Resets the array pointer of the storage
+        *
+        * @return void
+        */
+       public function rewind() {
+               $realInstance = $this->_loadRealInstance();
+               reset($realInstance);
+       }
+
+       /**
+        * Checks if the array pointer of the storage points to a valid position
+        *
+        * @return void
+        */
+       public function valid() {
+               return $this->current() !== FALSE;
+       }
+
+       
+       
 }
-?>
\ No newline at end of file
+?>