* renamed identifier to uid (necessary for generic reconstitution)
authorJochen Rau <j.rau@web.de>
Tue, 27 Jan 2009 22:42:44 +0000 (22:42 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 27 Jan 2009 22:42:44 +0000 (22:42 +0000)
* added a reconstituteProperty() method in the AbstractDomainModel
* removed setter for uid (fka identifier)

typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_Argument.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_RESTController.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_RequestHandlingController.php
typo3/sysext/extbase/Classes/Persistence/TX_EXTMVC_Persistence_ClassSchema.php
typo3/sysext/extbase/Classes/Persistence/TX_EXTMVC_Persistence_ClassSchemataBuilder.php
typo3/sysext/extbase/Classes/Persistence/TX_EXTMVC_Persistence_Repository.php
typo3/sysext/extbase/Classes/Persistence/TX_EXTMVC_Persistence_Session.php
typo3/sysext/extbase/Classes/TX_EXTMVC_AbstractDomainObject.php
typo3/sysext/extbase/Classes/TX_EXTMVC_EntityObject.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_TemplateView.php

index cc24228..a011514 100644 (file)
@@ -125,10 +125,10 @@ class Argument {
        protected $propertyConverterInputFormat = 'string';
 
        /**
-        * Identifier for the argument, if it has one
+        * Uid for the argument, if it has one
         * @var string
         */
-       protected $identifier = NULL;
+       protected $uid = NULL;
 
        /**
         * Constructs this controller argument
@@ -492,24 +492,24 @@ class Argument {
        }
 
        /**
-        * Set the identifier for the argument.
+        * Set the uid for the argument.
         *
-        * @param string $identifier The identifier for the argument.
+        * @param string $uid The uid for the argument.
         * @return void
         * @author Sebastian Kurfürst <sebastian@typo3.org>
         */
-       public function setIdentifier($identifier) {
-               $this->identifier = $identifier;
+       public function setUid($uid) {
+               $this->uid = $uid;
        }
 
        /**
-        * Get the identifier of the argument, if it has one.
+        * Get the uid of the argument, if it has one.
         *
-        * @return string Identifier of the argument. If none set, returns NULL.
+        * @return string Uid of the argument. If none set, returns NULL.
         * @author Sebastian Kurfürst <sebastian@typo3.org>
         */
-       public function getIdentifier() {
-               return $this->identifier;
+       public function getUid() {
+               return $this->uid;
        }
 
        /**
index 1bcb069..4b2c819 100644 (file)
@@ -77,7 +77,7 @@ class RESTController extends TX_EXTMVC_Controller_ActionController {
                                        $actionName = 'create';
                                break;
                                case F3_FLOW3_Utility_Environment::REQUEST_METHOD_PUT :
-                                       if ($this->arguments['id']->getValue() === NULL) $this->throwStatus(400, NULL, 'Invalid identifier');
+                                       if ($this->arguments['id']->getValue() === NULL) $this->throwStatus(400, NULL, 'Invalid uid');
                                        $actionName = 'update';
                                break;
                                case F3_FLOW3_Utility_Environment::REQUEST_METHOD_DELETE :
@@ -96,7 +96,7 @@ class RESTController extends TX_EXTMVC_Controller_ActionController {
         * by the action methods.
         *
         * NOTE: If you override this method, don't forget to call the parent
-        * method as well (or define the identifier own your own).
+        * method as well (or define the uid own your own).
         *
         * @return void
         * @author Robert Lemke <robert@typo3.org>
index 695d498..7a48880 100644 (file)
@@ -236,8 +236,8 @@ class TX_EXTMVC_Controller_RequestHandlingController extends TX_EXTMVC_Controlle
                        if (isset($this->arguments[$propertyName])) $this->arguments[$propertyName]->addWarning($warning);
                }
 
-               foreach ($this->argumentMappingResults->getIdentifiers() as $propertyName => $identifier) {
-                       if (isset($this->arguments[$propertyName])) $this->arguments[$propertyName]->setIdentifier($identifier);
+               foreach ($this->argumentMappingResults->getUids() as $propertyName => $uid) {
+                       if (isset($this->arguments[$propertyName])) $this->arguments[$propertyName]->setUid($uid);
                }
        }
 }
index 92de620..b4a5822 100644 (file)
@@ -49,11 +49,11 @@ class ClassSchema {
        protected $modelType = self::MODELTYPE_ENTITY;
 
        /**
-        * The name of the property holding the identifier of an entity, if any.
+        * The name of the property holding the uid of an entity, if any.
         *
         * @var string
         */
-       protected $identifierProperty;
+       protected $uidProperty;
 
        /**
         * Properties of the class which need to be persisted
@@ -144,24 +144,24 @@ class ClassSchema {
        }
 
        /**
-        * Sets the property marked as identifier of an object with @identifier
+        * Sets the property marked as uid of an object with @uid
         *
         * @param string $name
         * @return void
         * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function setIdentifierProperty($name) {
-               $this->identifierProperty = $name;
+       public function setUidProperty($name) {
+               $this->uidProperty = $name;
        }
 
        /**
-        * Gets the name of the property marked as identifier of an object
+        * Gets the name of the property marked as uid of an object
         *
         * @return string
         * @author Karsten Dambekalns <karsten@typo3.org>
         */
-       public function getIdentifierProperty() {
-               return $this->identifierProperty;
+       public function getUidProperty() {
+               return $this->uidProperty;
        }
 
 }
index 62a6505..f675626 100644 (file)
@@ -74,8 +74,8 @@ class ClassSchemataBuilder {
                        $classSchema = new TX_EXTMVC_Persistence_ClassSchema($className);
                        $classSchema->setModelType($modelType);
                        foreach ($this->reflectionService->getClassPropertyNames($className) as $propertyName) {
-                               if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'identifier')) {
-                                       $classSchema->setIdentifierProperty($propertyName);
+                               if ($this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'uid')) {
+                                       $classSchema->setUidProperty($propertyName);
                                }
                                if (!$this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'transient') && $this->reflectionService->isPropertyTaggedWith($className, $propertyName, 'var')) {
                                        $classSchema->setProperty($propertyName, implode(' ', $this->reflectionService->getPropertyTagValues($className, $propertyName, 'var')));
index fbade1e..f32620e 100644 (file)
@@ -99,7 +99,7 @@ class TX_EXTMVC_Persistence_Repository implements TX_EXTMVC_Persistence_Reposito
         * @return void
         * @author Jochen Rau <jochen.rau@typoplanet.de>
         */
-       public function persistAll() {          
+       public function persistAll() {
                if ($this->session->getRemovedObjects()->count() > 0) $this->deleteRemoved();
                if ($this->session->getAddedObjects()->count() > 0) $this->insertAdded();
                // if ($this->session->getDirtyObjects()->count() > 0) $this->updateDirty();
index 97d1dc0..e758941 100644 (file)
@@ -55,13 +55,6 @@ class TX_EXTMVC_Persistence_Session implements t3lib_singleton {
         */
        protected $reconstitutedObjects;
 
-       /**
-        * Clean objects
-        *
-        * @var TX_EXTMVC_Persistence_ObjectStorage
-        */
-       protected $cleanObjects;
-
        /**
         * Repositories
         *
@@ -78,7 +71,6 @@ class TX_EXTMVC_Persistence_Session implements t3lib_singleton {
                $this->addedObjects = new TX_EXTMVC_Persistence_ObjectStorage();
                $this->removedObjects = new TX_EXTMVC_Persistence_ObjectStorage();
                $this->reconstitutedObjects = new TX_EXTMVC_Persistence_ObjectStorage();
-               $this->cleanObjects = new TX_EXTMVC_Persistence_ObjectStorage();
        }
 
        /**
@@ -137,8 +129,6 @@ class TX_EXTMVC_Persistence_Session implements t3lib_singleton {
         */
        public function registerReconstitutedObject(TX_EXTMVC_AbstractDomainObject $object) {
                $this->reconstitutedObjects->attach($object);
-               $object->memorizeCleanObjectState();
-               $this->memorizeCleanObjectState($object);
        }
 
        /**
@@ -151,17 +141,6 @@ class TX_EXTMVC_Persistence_Session implements t3lib_singleton {
                return $this->reconstitutedObjects;
        }
        
-       /**
-        * Memorizes a clone of an object to represent it's state at a given time.
-        *
-        * @param object $object
-        * @return TX_EXTMVC_AbstractDomainObject
-        * @author Jochen Rau <jochen.rau@typoplanet.de>
-        */
-       public function memorizeCleanObjectState(TX_EXTMVC_AbstractDomainObject $object) {
-               $this->cleanObjects->attach(clone($object));
-       }
-
        public function getDirtyObjects() {
                // return NULL;
        }       
index cbf3c5d..3dd664e 100644 (file)
@@ -29,36 +29,63 @@ declare(ENCODING = 'utf-8');
  */
 abstract class TX_EXTMVC_AbstractDomainObject {
        
-       private $cleanProperties;
-       
        /**
-        * Stores the unchanged values of the database fields to compare
-        * them with the values at commit time.
+        * An array of properties filled with database values of columns configured in $TCA.
         *
-        * @return void
-        * @author Jochen Rau <jochen.rau@typoplanet.de>
+        * @var array
         */
-       public function memorizeCleanObjectState() {
-               $possibleTableName = strtolower(get_class($this));
-               t3lib_div::loadTCA($possibleTableName);
-               $tca = $GLOBALS['TCA'][$possibleTableName]['columns'];
-               $properties = array_flip(array_keys($tca));
-               foreach ($properties as $propertyName => $propertyValue) {
-                       $this->cleanProperties[$this->underscoreToCamelCase($propertyName)] = 'clean value';
+       private $cleanProperties = NULL;
+       
+       private function initCleanProperties() {
+                       $possibleTableName = strtolower(get_class($this));
+                       t3lib_div::loadTCA($possibleTableName);
+                       $tca = $GLOBALS['TCA'][$possibleTableName]['columns'];
+                       $tcaColumns = array_keys($tca);
+                       foreach ($tcaColumns as $columnName) {
+                               $this->cleanProperties[$columnName] = NULL;
+                       }
+               return array_key_exists($propertyName, $this->cleanProperties);
+       }
+               
+       private function isConfiguredInTca($propertyName) {
+               return array_key_exists($propertyName, $this->cleanProperties);
+       }
+               
+       public function reconstituteProperty($propertyName, $value) {
+               if ($this->cleanProperties === NULL) {
+                       $this->initCleanProperties();
+               }
+               $possibleSetterMethodName = 'set' . ucfirst($propertyName);
+               $possibleAddMethodName = 'add' . ucfirst($propertyName);
+               if (method_exists($this, $possibleSetterMethodName)) {
+                       $this->$possibleSetterMethodName($value);
+               } elseif (method_exists($this, $possibleAddMethodName)) {
+                       $this->$possibleAddMethodName($value);
+               } else {
+                       if (property_exists($this, $propertyName)) {
+                               $this->$propertyName = $value;
+                       }
+               }
+               if ($this->isConfiguredInTca($propertyName)) {
+                       $this->cleanProperties[$propertyName] = $value;                 
                }
        }
-       
+               
        /**
-        * Returns given string as CamelCased
+        * Returns a given string as UpperCamelCase
         *
-        * @param       string  String to convert to camel case
+        * @param       string  String to be converted to camel case
         * @return      string  UpperCamelCasedWord
         */
-       protected function underscoreToCamelCase($string) {
+       private function underscoreToCamelCase($string) {
                $upperCamelCase = (str_replace(' ', '', ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', strtolower($string)))));
-               $lowerCamelCase = strtolower( substr($upperCamelCase,0,1) ) . substr($upperCamelCase,1);
+               $lowerCamelCase = $this->lowercaseFirst($upperCamelCase);
                return $lowerCamelCase;
        }
        
+       private function lowercaseFirst($string) {
+               return strtolower(substr($string,0,1) ) . substr($string,1);
+       }
+       
 }
 ?>
\ No newline at end of file
index bb16d96..fe5df41 100644 (file)
@@ -32,29 +32,18 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_AbstractDomain
 class TX_EXTMVC_EntityObject extends TX_EXTMVC_AbstractDomainObject {
 
        /**
-        * @var string The identifier
+        * @var string The uid
         */
-       protected $identifier;
+       protected $uid;
 
        /**
-        * Sets the identifier. Should only be set once at instatiation time!
-        *
-        * @param string $identifier The identifier
-        * @return void
-        * @author Jochen Rau <jochen.rau@typoplanet.de>
-        */
-       public function setIdentifier($identifier) {
-               $this->identifier = $identifier;
-       }
-
-       /**
-        * Getter for identifier
+        * Getter for uid
         *
         * @return string
         * @author Jochen Rau <jochen.rau@typoplanet.de>
         */
-       public function getIdentifier() {
-               return $this->identifier;
+       public function getUid() {
+               return $this->uid;
        }
        
 }
index f387dd9..86d8f90 100644 (file)
@@ -39,7 +39,7 @@ class TX_EXTMVC_View_TemplateView extends TX_EXTMVC_View_AbstractView {
        protected $templateFilePattern = 'Resources/Template/@controller/@action.xhtml';
 
        /**
-        * @var array Marker identifiers and their replacement content
+        * @var array Marker uids and their replacement content
         */
        protected $markers = array();