예제 #1
0
 /**
  * Copy a singe object based on field annotations about how to copy the object
  *
  * @param Tx_Extbase_DomainObject_DomainObjectInterface $object The object to be copied
  * @return Tx_Extbase_DomainObject_DomainObjectInterface $copy
  * @api
  */
 public function copy($object)
 {
     $className = get_class($object);
     $this->recursionService->in();
     $this->recursionService->check($className);
     $copy = $this->objectManager->get($className);
     $properties = $this->reflectionService->getClassPropertyNames($className);
     foreach ($properties as $propertyName) {
         $tags = $this->reflectionService->getPropertyTagsValues($className, $propertyName);
         $getter = 'get' . ucfirst($propertyName);
         $setter = 'set' . ucfirst($propertyName);
         $copyMethod = $tags['copy'][0];
         $copiedValue = NULL;
         if ($copyMethod !== NULL && $copyMethod !== 'ignore') {
             $originalValue = $object->{$getter}();
             if ($copyMethod == 'reference') {
                 $copiedValue = $this->copyAsReference($originalValue);
             } elseif ($copyMethod == 'clone') {
                 $copiedValue = $this->copyAsClone($originalValue);
             }
             if ($copiedValue != NULL) {
                 $copy->{$setter}($copiedValue);
             }
         }
     }
     $this->recursionService->out();
     return $copy;
 }
예제 #2
0
 /**
  * Returns an array of annotations for $propertyName on $object
  *
  * @param mixed $object
  * @param string $propertyName
  * @return array
  * @api
  */
 public function getAnnotationsByProperty($object, $propertyName)
 {
     if (is_object($object)) {
         $className = get_class($object);
     } else {
         $className = $object;
     }
     return $this->reflectionService->getPropertyTagsValues($className, $propertyName);
 }
예제 #3
0
 /**
  * Builds a base validator conjunction for the given data type.
  *
  * The base validation rules are those which were declared directly in a class (typically
  * a model) through some @validate annotations on properties.
  *
  * Additionally, if a custom validator was defined for the class in question, it will be added
  * to the end of the conjunction. A custom validator is found if it follows the naming convention
  * "Replace '\Model\' by '\Validator\' and append "Validator".
  *
  * Example: $dataType is F3\Foo\Domain\Model\Quux, then the Validator will be found if it has the
  * name F3\Foo\Domain\Validator\QuuxValidator
  *
  * @param string $dataType The data type to build the validation conjunction for. Needs to be the fully qualified object name.
  * @return Tx_Extbase_Validation_Validator_ConjunctionValidator The validator conjunction or NULL
  */
 protected function buildBaseValidatorConjunction($dataType)
 {
     $validatorConjunction = $this->objectManager->get('Tx_Extbase_Validation_Validator_ConjunctionValidator');
     // Model based validator
     if (strstr($dataType, '_') !== FALSE && class_exists($dataType)) {
         $validatorCount = 0;
         $objectValidator = $this->createValidator('GenericObject');
         foreach ($this->reflectionService->getClassPropertyNames($dataType) as $classPropertyName) {
             $classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($dataType, $classPropertyName);
             if (!isset($classPropertyTagsValues['validate'])) {
                 continue;
             }
             foreach ($classPropertyTagsValues['validate'] as $validateValue) {
                 $parsedAnnotation = $this->parseValidatorAnnotation($validateValue);
                 foreach ($parsedAnnotation['validators'] as $validatorConfiguration) {
                     $newValidator = $this->createValidator($validatorConfiguration['validatorName'], $validatorConfiguration['validatorOptions']);
                     if ($newValidator === NULL) {
                         throw new Tx_Extbase_Validation_Exception_NoSuchValidator('Invalid validate annotation in ' . $dataType . '::' . $classPropertyName . ': Could not resolve class name for  validator "' . $validatorConfiguration['validatorName'] . '".', 1241098027);
                     }
                     $objectValidator->addPropertyValidator($classPropertyName, $newValidator);
                     $validatorCount++;
                 }
             }
         }
         if ($validatorCount > 0) {
             $validatorConjunction->addValidator($objectValidator);
         }
     }
     // Custom validator for the class
     $possibleValidatorClassName = str_replace('_Model_', '_Validator_', $dataType) . 'Validator';
     $customValidator = $this->createValidator($possibleValidatorClassName);
     if ($customValidator !== NULL) {
         $validatorConjunction->addValidator($customValidator);
     }
     return $validatorConjunction;
 }
예제 #4
0
 /**
  * Does the target $propertyName on $className contain a data type which supports inflation?
  *
  * @param string $className String class name of the class being inflated
  * @param string $propertyName String name of property being inflated on class
  * @param string $propertyType String type of the property being inflated according to input, asserted against blacklist
  * @return boolean
  */
 protected function assertSupportsInflation($className, $propertyName, $propertyType)
 {
     $tags = $this->reflectionService->getPropertyTagsValues($className, $propertyName);
     if (TRUE === isset($tags['dontmarshall'])) {
         return FALSE;
     }
     return TRUE;
 }