public function get($class)
 {
     $c = array();
     if (class_exists($class)) {
         $c = array();
         // Loac Class Annotations
         foreach ($this->reflectionService->getClassAnnotations($class) as $key => $object) {
             $shortName = $this->convertAnnotationName(get_class($object));
             if (!isset($c[$shortName])) {
                 $c[$shortName] = array();
             }
             $c[$shortName][] = $object;
         }
         $schema = $this->reflectionService->getClassSchema($class);
         if (is_object($schema)) {
             if (!isset($c["repository"])) {
                 $c["repository"] = array(new \Admin\Annotations\Repository(array("class" => $schema->getRepositoryClassName())));
             }
             $properties = $schema->getProperties();
         } else {
             $properties = array_flip($this->reflectionService->getClassPropertyNames($class));
         }
         foreach ($properties as $property => $meta) {
             if ($property == "FLOW3_Persistence_Identifier") {
                 continue;
             }
             $c["properties"][$property] = array();
             // Load legacy Annotations like @var,...
             foreach ($this->reflectionService->getPropertyTagsValues($class, $property) as $shortName => $tags) {
                 if (!isset($c["properties"][$property])) {
                     $c["properties"][$property] = array();
                 }
                 $c["properties"][$property][$shortName] = $tags;
             }
             // $c["properties"][$property]["type"] = array(
             // 	new \Admin\Annotations\Type(array(
             // 		"name" => $meta["type"],
             // 		"subtype" => $meta["elementType"],
             // 	))
             // );
             // Load Annotations and override legacy Annotations
             $annotations = $this->reflectionService->getPropertyAnnotations($class, $property);
             foreach ($annotations as $key => $objects) {
                 $shortName = $this->convertAnnotationName($key);
                 if (!isset($c["properties"][$property])) {
                     $c["properties"][$property] = array();
                 }
                 $c["properties"][$property][$shortName] = $objects;
             }
         }
     }
     return $c;
 }
Пример #2
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.
  *
  * If a property holds a class for which a base validator exists, that property will be
  * checked as well, regardless of a validate annotation
  *
  * 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: $targetClassName is TYPO3\Foo\Domain\Model\Quux, then the validator will be found if it has the
  * name TYPO3\Foo\Domain\Validator\QuuxValidator
  *
  * @param string $indexKey The key to use as index in $this->baseValidatorConjunctions; calculated from target class name and validation groups
  * @param string $targetClassName The data type to build the validation conjunction for. Needs to be the fully qualified class name.
  * @param array $validationGroups The validation groups to build the validator for
  * @return void
  * @throws Exception\NoSuchValidatorException
  * @throws \InvalidArgumentException
  */
 protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups)
 {
     $conjunctionValidator = new ConjunctionValidator();
     $this->baseValidatorConjunctions[$indexKey] = $conjunctionValidator;
     if (class_exists($targetClassName)) {
         // Model based validator
         $objectValidator = new GenericObjectValidator(array());
         foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $classPropertyName) {
             $classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($targetClassName, $classPropertyName);
             try {
                 $parsedType = \TYPO3\FLOW3\Utility\TypeHandling::parseType(trim(implode('', $classPropertyTagsValues['var']), ' \\'));
             } catch (\TYPO3\FLOW3\Utility\Exception\InvalidTypeException $exception) {
                 throw new \InvalidArgumentException(sprintf(' @var annotation of ' . $exception->getMessage(), 'class "' . $targetClassName . '", property "' . $classPropertyName . '"'), 1315564744);
             }
             $propertyTargetClassName = $parsedType['type'];
             if (\TYPO3\FLOW3\Utility\TypeHandling::isCollectionType($propertyTargetClassName) === TRUE) {
                 $collectionValidator = $this->createValidator('TYPO3\\FLOW3\\Validation\\Validator\\CollectionValidator', array('elementType' => $parsedType['elementType'], 'validationGroups' => $validationGroups));
                 $objectValidator->addPropertyValidator($classPropertyName, $collectionValidator);
             } elseif (class_exists($propertyTargetClassName) && $this->objectManager->isRegistered($propertyTargetClassName) && $this->objectManager->getScope($propertyTargetClassName) === \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE) {
                 $validatorForProperty = $this->getBaseValidatorConjunction($propertyTargetClassName, $validationGroups);
                 if (count($validatorForProperty) > 0) {
                     $objectValidator->addPropertyValidator($classPropertyName, $validatorForProperty);
                 }
             }
             $validateAnnotations = $this->reflectionService->getPropertyAnnotations($targetClassName, $classPropertyName, 'TYPO3\\FLOW3\\Annotations\\Validate');
             foreach ($validateAnnotations as $validateAnnotation) {
                 if (count(array_intersect($validateAnnotation->validationGroups, $validationGroups)) === 0) {
                     // In this case, the validation groups for the property do not match current validation context
                     continue;
                 }
                 $newValidator = $this->createValidator($validateAnnotation->type, $validateAnnotation->options);
                 if ($newValidator === NULL) {
                     throw new \TYPO3\FLOW3\Validation\Exception\NoSuchValidatorException('Invalid validate annotation in ' . $targetClassName . '::' . $classPropertyName . ': Could not resolve class name for  validator "' . $validateAnnotation->type . '".', 1241098027);
                 }
                 $objectValidator->addPropertyValidator($classPropertyName, $newValidator);
             }
         }
         if (count($objectValidator->getPropertyValidators()) > 0) {
             $conjunctionValidator->addValidator($objectValidator);
         }
         // Custom validator for the class
         $possibleValidatorClassName = str_replace('\\Model\\', '\\Validator\\', $targetClassName) . 'Validator';
         $customValidator = $this->createValidator($possibleValidatorClassName);
         if ($customValidator !== NULL) {
             $conjunctionValidator->addValidator($customValidator);
         }
     }
 }