Example #1
0
 /**
  * Commits new objects and changes to objects in the current persistence
  * session into the backend
  *
  * @return void
  * @api
  */
 public function persistAll()
 {
     $aggregateRootObjects = new Tx_Extbase_Persistence_ObjectStorage();
     $removedObjects = new Tx_Extbase_Persistence_ObjectStorage();
     // fetch and inspect objects from all known repositories
     $repositoryClassNames = $this->getRepositoryClassNames();
     foreach ($repositoryClassNames as $repositoryClassName) {
         $repository = $this->objectManager->getObject($repositoryClassName);
         $aggregateRootObjects->addAll($repository->getAddedObjects());
         $removedObjects->addAll($repository->getRemovedObjects());
     }
     foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) {
         if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) {
             $aggregateRootObjects->attach($reconstitutedObject);
         }
     }
     // hand in only aggregate roots, leaving handling of subobjects to
     // the underlying storage layer
     $this->backend->setAggregateRootObjects($aggregateRootObjects);
     $this->backend->setDeletedObjects($removedObjects);
     $this->backend->commit();
     // this needs to unregister more than just those, as at least some of
     // the subobjects are supposed to go away as well...
     // OTOH those do no harm, changes to the unused ones should not happen,
     // so all they do is eat some memory.
     foreach ($removedObjects as $removedObject) {
         $this->session->unregisterReconstitutedObject($removedObject);
     }
 }
 /**
  * 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->getObject('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;
 }