示例#1
0
 /**
  * @param Task $task
  * @return boolean
  */
 protected function assertValidTask(Task $task)
 {
     if (!class_exists($task->getImplementation())) {
         throw new \InvalidArgumentException(sprintf('Task implementation "%s" must exist', $task->getImplementation()), 1419296545);
     }
     if (!$this->reflexionService->isClassImplementationOf($task->getImplementation(), self::TASK_INTERFACE)) {
         throw new \InvalidArgumentException('Task must implement TaskInterface', 1419296485);
     }
 }
示例#2
0
 /**
  * Returns Mapper-Service configured for CAS Provider.
  *
  * @param string $providerName provider name to fetch a mapper from.
  *
  * @throws \RafaelKa\JasigPhpCas\Exception\InvalidConfigurationException
  * @throws \RafaelKa\JasigPhpCas\Exception\InvalidClassDefinitionForMapperException
  *
  * @return \RafaelKa\JasigPhpCas\Service\MapperInterface
  */
 private function getMapperByProviderName($providerName)
 {
     if (!empty($this->providerMappers[$providerName])) {
         return $this->providerMappers[$providerName];
     }
     $mapperClassName = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.Flow.security.authentication.providers.' . $providerName . 'Mapping.MapperClass');
     if (empty($mapperClassName)) {
         $mapperClassName = self::DEFAULT_CAS_MAPPER;
     } else {
         if (!class_exists($mapperClassName)) {
             throw new \RafaelKa\JasigPhpCas\Exception\InvalidConfigurationException(sprintf('Class "%s" configured in Settings.yaml at "TYPO3.Flow.security.authentication.providers.%s.Mapping.MapperClass" does not exists.', $mapperClassName, $providerName), 1370983932);
         }
         if (!$this->reflectionService->isClassImplementationOf($mapperClassName, 'RafaelKa\\JasigPhpCas\\Service\\MapperInterface')) {
             throw new \RafaelKa\JasigPhpCas\Exception\InvalidClassDefinitionForMapperException(sprintf('Class "%s" configured in Settings.yaml at "TYPO3.Flow.security.authentication.providers.%s.MapperClass" is not implementation of "RafaelKa\\JasigPhpCas\\Service\\MapperInterface". Please rediclare "%s" as "\\TYPO3\\Flow\\Security\\Authentication\\TokenInterface" adapter Class.', $mapperClassName, $providerName, $mapperClassName), 1370981664);
         }
         if (!$this->reflectionService->getClassAnnotation($mapperClassName, 'TYPO3\\Flow\\Annotations\\Scope')->value !== 'singleton') {
             throw new \RafaelKa\JasigPhpCas\Exception\InvalidClassDefinitionForMapperException(sprintf('Class "%s" configured in Settings.yaml at "TYPO3.Flow.security.authentication.providers.%s.MapperClass" is not a singleton. Please declare "%s" as "@Flow\\Scope("singleton")" Class.', $mapperClassName, $providerName, $mapperClassName), 1371036890);
         }
     }
     $this->providerMappers[$providerName] = $this->objectManager->get($mapperClassName);
     return $this->providerMappers[$providerName];
 }
 /**
  * Returns instance of concrete formatter.
  *
  * The type provided has to be either a name of existing class placed in
  * \TYPO3\Flow\I18n\Formatter namespace or a fully qualified class name;
  * in both cases implementing this' package's FormatterInterface.
  * For example, when $formatterName is 'number',
  * the \TYPO3\Flow\I18n\Formatter\NumberFormatter class has to exist; when
  * $formatterName is 'Acme\Foobar\I18nFormatter\SampleFormatter', this class
  * must exist and implement TYPO3\Flow\I18n\Formatter\FormatterInterface.
  *
  * Throws exception if there is no formatter for name given or one could be
  * retrieved but does not satisfy the FormatterInterface.
  *
  * @param string $formatterType Either one of the built-in formatters or fully qualified formatter class name
  * @return \TYPO3\Flow\I18n\Formatter\FormatterInterface The concrete formatter class
  * @throws \TYPO3\Flow\I18n\Exception\UnknownFormatterException When formatter for a name given does not exist
  * @throws \TYPO3\Flow\I18n\Exception\InvalidFormatterException When formatter for a name given does not exist
  */
 protected function getFormatter($formatterType)
 {
     $foundFormatter = false;
     $formatterType = ltrim($formatterType, '\\');
     if (isset($this->formatters[$formatterType])) {
         $foundFormatter = $this->formatters[$formatterType];
     }
     if ($foundFormatter === false) {
         if ($this->objectManager->isRegistered($formatterType)) {
             $possibleClassName = $formatterType;
         } else {
             $possibleClassName = sprintf('TYPO3\\Flow\\I18n\\Formatter\\%sFormatter', ucfirst($formatterType));
             if (!$this->objectManager->isRegistered($possibleClassName)) {
                 throw new \TYPO3\Flow\I18n\Exception\UnknownFormatterException('Could not find formatter for "' . $formatterType . '".', 1278057791);
             }
         }
         if (!$this->reflectionService->isClassImplementationOf($possibleClassName, \TYPO3\Flow\I18n\Formatter\FormatterInterface::class)) {
             throw new \TYPO3\Flow\I18n\Exception\InvalidFormatterException('The resolved internationalization formatter class name "' . $possibleClassName . '" does not implement "TYPO3\\Flow\\I18n\\Formatter\\FormatterInterface" as required.', 1358162557);
         }
         $foundFormatter = $this->objectManager->get($possibleClassName);
     }
     $this->formatters[$formatterType] = $foundFormatter;
     return $foundFormatter;
 }
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  * @return void
  * @throws MappingException
  * @throws \UnexpectedValueException
  * @todo adjust when Doctrine 2.5 is used, see http://www.doctrine-project.org/jira/browse/DDC-93
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /**
      * This is the actual type we have at this point, but we cannot change the
      * signature due to inheritance.
      *
      * @var OrmClassMetadata $metadata
      */
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($class->getName());
     $classAnnotations = $this->reader->getClassAnnotations($class);
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
         $mappedSuperclassAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
         if ($mappedSuperclassAnnotation->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnotation->repositoryClass);
         }
         $metadata->isMappedSuperclass = true;
     } elseif (isset($classAnnotations[\TYPO3\Flow\Annotations\Entity::class]) || isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnotation = isset($classAnnotations[\TYPO3\Flow\Annotations\Entity::class]) ? $classAnnotations[\TYPO3\Flow\Annotations\Entity::class] : $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnotation->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnotation->repositoryClass);
         } elseif ($classSchema->getRepositoryClassName() !== null) {
             if ($this->reflectionService->isClassImplementationOf($classSchema->getRepositoryClassName(), 'Doctrine\\ORM\\EntityRepository')) {
                 $metadata->setCustomRepositoryClass($classSchema->getRepositoryClassName());
             }
         }
         if ($entityAnnotation->readOnly) {
             $metadata->markReadOnly();
         }
     } elseif ($classSchema->getModelType() === ClassSchema::MODELTYPE_VALUEOBJECT) {
         // also ok... but we make it read-only
         $metadata->markReadOnly();
     } else {
         throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     // Evaluate Table annotation
     $primaryTable = array();
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnotation->name, 'schema' => $tableAnnotation->schema);
         if ($tableAnnotation->indexes !== null) {
             foreach ($tableAnnotation->indexes as $indexAnnotation) {
                 $index = array('columns' => $indexAnnotation->columns);
                 if (!empty($indexAnnotation->name)) {
                     $primaryTable['indexes'][$indexAnnotation->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnotation->uniqueConstraints !== null) {
             foreach ($tableAnnotation->uniqueConstraints as $uniqueConstraint) {
                 $uniqueConstraint = array('columns' => $uniqueConstraint->columns);
                 if (!empty($uniqueConstraint->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
         if ($tableAnnotation->options !== null) {
             $primaryTable['options'] = $tableAnnotation->options;
         }
     }
     if (!isset($primaryTable['name'])) {
         $className = $classSchema->getClassName();
         $primaryTable['name'] = $this->inferTableNameFromClassName($className);
     }
     // Evaluate NamedNativeQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'])) {
         $namedNativeQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'];
         foreach ($namedNativeQueriesAnnotation->value as $namedNativeQuery) {
             $metadata->addNamedNativeQuery(array('name' => $namedNativeQuery->name, 'query' => $namedNativeQuery->query, 'resultClass' => $namedNativeQuery->resultClass, 'resultSetMapping' => $namedNativeQuery->resultSetMapping));
         }
     }
     // Evaluate SqlResultSetMappings annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
         $sqlResultSetMappingsAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
         foreach ($sqlResultSetMappingsAnnotation->value as $resultSetMapping) {
             $entities = array();
             $columns = array();
             foreach ($resultSetMapping->entities as $entityResultAnnotation) {
                 $entityResult = array('fields' => array(), 'entityClass' => $entityResultAnnotation->entityClass, 'discriminatorColumn' => $entityResultAnnotation->discriminatorColumn);
                 foreach ($entityResultAnnotation->fields as $fieldResultAnnotation) {
                     $entityResult['fields'][] = array('name' => $fieldResultAnnotation->name, 'column' => $fieldResultAnnotation->column);
                 }
                 $entities[] = $entityResult;
             }
             foreach ($resultSetMapping->columns as $columnResultAnnotation) {
                 $columns[] = array('name' => $columnResultAnnotation->name);
             }
             $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping->name, 'entities' => $entities, 'columns' => $columns));
         }
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnotation->value)) {
             throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
         }
         foreach ($namedQueriesAnnotation->value as $namedQuery) {
             if (!$namedQuery instanceof NamedQuery) {
                 throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $inheritanceType = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($inheritanceTypeAnnotation->value));
         if ($inheritanceType !== OrmClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discriminatorColumnAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $discriminatorColumn = array('name' => $discriminatorColumnAnnotation->name, 'type' => $discriminatorColumnAnnotation->type, 'length' => $discriminatorColumnAnnotation->length, 'columnDefinition' => $discriminatorColumnAnnotation->columnDefinition);
             } else {
                 $discriminatorColumn = array('name' => 'dtype', 'type' => 'string', 'length' => 255);
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discriminatorMapAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $discriminatorMap = $discriminatorMapAnnotation->value;
             } else {
                 $discriminatorMap = array();
                 $subclassNames = $this->reflectionService->getAllSubClassNamesForClass($className);
                 if (!$this->reflectionService->isClassAbstract($className)) {
                     $mappedClassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $className)));
                     $discriminatorMap[$mappedClassName] = $className;
                 }
                 foreach ($subclassNames as $subclassName) {
                     $mappedSubclassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $subclassName)));
                     $discriminatorMap[$mappedSubclassName] = $subclassName;
                 }
             }
             if ($discriminatorMap !== array()) {
                 $metadata->setDiscriminatorColumn($discriminatorColumn);
                 $metadata->setDiscriminatorMap($discriminatorMap);
             } else {
                 $inheritanceType = OrmClassMetadata::INHERITANCE_TYPE_NONE;
             }
         }
         $metadata->setInheritanceType($inheritanceType);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($changeTrackingAnnotation->value)));
     } else {
         $metadata->setChangeTrackingPolicy(OrmClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
     }
     // Evaluate annotations on properties/fields
     try {
         $this->evaluatePropertyAnnotations($metadata);
     } catch (MappingException $exception) {
         throw new MappingException(sprintf('Failure while evaluating property annotations for class "%s": %s', $metadata->getName(), $exception->getMessage()), 1382003497, $exception);
     }
     // build unique index for table
     if (!isset($primaryTable['uniqueConstraints'])) {
         $idProperties = array_keys($classSchema->getIdentityProperties());
         if (array_diff($idProperties, $metadata->getIdentifierFieldNames()) !== array()) {
             $uniqueIndexName = $this->truncateIdentifier('flow_identity_' . $primaryTable['name']);
             foreach ($idProperties as $idProperty) {
                 $primaryTable['uniqueConstraints'][$uniqueIndexName]['columns'][] = isset($metadata->columnNames[$idProperty]) ? $metadata->columnNames[$idProperty] : strtolower($idProperty);
             }
         }
     }
     $metadata->setPrimaryTable($primaryTable);
     // Evaluate AssociationOverrides annotation
     $this->evaluateOverridesAnnotations($classAnnotations, $metadata);
     // Evaluate EntityListeners annotation
     $this->evaluateEntityListenersAnnotation($class, $metadata, $classAnnotations);
     // Evaluate @HasLifecycleCallbacks annotation
     $this->evaluateLifeCycleAnnotations($class, $metadata);
 }