コード例 #1
0
ファイル: Navigation.php プロジェクト: renepardon/FLOW3-Admin
 /**
  * Add the Annotated Method to the Navigation
  *
  * @param \TYPO3\FLOW3\AOP\JoinPointInterface $joinPoint
  * @FLOW3\Before("method(public .*\Controller\.*Controller->.*Action(.*))")
  * @return void
  */
 public function addNavigationitem(\TYPO3\FLOW3\AOP\JoinPointInterface $joinPoint)
 {
     $currentClassName = $joinPoint->getClassName();
     $currentMethodName = $joinPoint->getMethodName();
     $controllers = $this->reflectionService->getAllSubClassNamesForClass("\\TYPO3\\FLOW3\\MVC\\Controller\\ActionController");
     foreach ($controllers as $className) {
         $methods = get_class_methods($className);
         if (is_array($methods)) {
             foreach ($methods as $methodName) {
                 if ($this->reflectionService->isMethodAnnotatedWith($className, $methodName, "Admin\\Annotations\\Navigation")) {
                     $annotations = $this->reflectionService->getMethodAnnotations($className, $methodName, "Admin\\Annotations\\Navigation");
                     foreach ($annotations as $annotation) {
                         $action = str_replace("Action", "", $methodName);
                         $controller = $this->helper->getControllerByClassName($className);
                         $package = $this->objectManager->getPackageKeyByObjectName($className);
                         $arguments = array("action" => $action, "controller" => $controller, "package" => $package);
                         $title = !is_null($annotation->title) ? $annotation->title : sprintf("%s (%s)", $controller, $action);
                         \Admin\Core\API::addNavigationitem($title, $annotation->position, $arguments, $annotation->priority, $annotation->parent);
                     }
                 }
             }
         }
     }
     $settings = $this->helper->getSettings("Admin.Navigation");
     foreach ($settings as $position => $items) {
         foreach ($items as $title => $conf) {
             $priority = isset($conf["priority"]) ? $conf["priority"] : 100;
             $arguments = $conf["Arguments"];
             \Admin\Core\API::addNavigationitem($title, strtolower($position), $arguments, $priority);
         }
     }
 }
コード例 #2
0
ファイル: CommandManager.php プロジェクト: nxpthx/FLOW3
 /**
  * Returns an array of all commands
  *
  * @return array<Command>
  * @api
  */
 public function getAvailableCommands()
 {
     if ($this->availableCommands === NULL) {
         $this->availableCommands = array();
         $commandControllerClassNames = $this->reflectionService->getAllSubClassNamesForClass('TYPO3\\FLOW3\\Cli\\CommandController');
         foreach ($commandControllerClassNames as $className) {
             if (!class_exists($className)) {
                 continue;
             }
             foreach (get_class_methods($className) as $methodName) {
                 if (substr($methodName, -7, 7) === 'Command') {
                     $this->availableCommands[] = new Command($className, substr($methodName, 0, -7));
                 }
             }
         }
     }
     return $this->availableCommands;
 }
コード例 #3
0
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\FLOW3\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     if (interface_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllImplementationClassNamesForInterface($this->interfaceOrClassName);
     } elseif (class_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllSubClassNamesForClass($this->interfaceOrClassName);
         $classNames[] = $this->interfaceOrClassName;
     } else {
         $classNames = array();
     }
     $filteredIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $filteredIndex->setClassNames($classNames);
     return $classNameIndex->intersect($filteredIndex);
 }
コード例 #4
0
 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
  * @return void
  * @throws \Doctrine\ORM\Mapping\MappingException
  * @throws \UnexpectedValueException
  * @todo adjust when Doctrine 2 supports value objects, see http://www.doctrine-project.org/jira/browse/DDC-93
  */
 public function loadMetadataForClass($className, \Doctrine\ORM\Mapping\ClassMetadataInfo $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\\FLOW3\\Annotations\\Entity']) || isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnotation = isset($classAnnotations['TYPO3\\FLOW3\\Annotations\\Entity']) ? $classAnnotations['TYPO3\\FLOW3\\Annotations\\Entity'] : $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() === \TYPO3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT) {
         // also ok... but we make it read-only
         $metadata->markReadOnly();
     } else {
         throw \Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     // Evaluate Table annotation
     $primaryTable = array();
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable['name'] = $tableAnnotation->name;
         $primaryTable['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 (!isset($primaryTable['name'])) {
         $className = $classSchema->getClassName();
         $primaryTable['name'] = $this->inferTableNameFromClassName($className);
     }
     // 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 \Doctrine\ORM\Mapping\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'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($inheritanceTypeAnnotation->value)));
         if ($metadata->inheritanceType !== \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discriminatorColumnAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discriminatorColumnAnnotation->name, 'type' => $discriminatorColumnAnnotation->type, 'length' => $discriminatorColumnAnnotation->length));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discriminatorMapAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($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;
                 }
                 $metadata->setDiscriminatorMap($discriminatorMap);
             }
         }
     }
     // 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(\Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
     }
     // Evaluate annotations on properties/fields
     $this->evaluatePropertyAnnotations($metadata);
     // build unique index for table
     if (!isset($primaryTable['uniqueConstraints'])) {
         $idProperties = array_keys($classSchema->getIdentityProperties());
         if (array_diff($idProperties, $metadata->getIdentifierFieldNames()) !== array()) {
             $uniqueIndexName = $this->truncateIdentifier('flow3_identity_' . $primaryTable['name']);
             foreach ($idProperties as $idProperty) {
                 $primaryTable['uniqueConstraints'][$uniqueIndexName]['columns'][] = isset($metadata->columnNames[$idProperty]) ? $metadata->columnNames[$idProperty] : strtolower($idProperty);
             }
         }
     }
     $metadata->setPrimaryTable($primaryTable);
     // Evaluate @HasLifecycleCallbacks annotation
     $this->evaluateLifeCycleAnnotations($class, $metadata);
 }