當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AnnotationReader::getClassAnnotations方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Annotations\AnnotationReader::getClassAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:PHP AnnotationReader::getClassAnnotations方法的具體用法?PHP AnnotationReader::getClassAnnotations怎麽用?PHP AnnotationReader::getClassAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Annotations\AnnotationReader的用法示例。


在下文中一共展示了AnnotationReader::getClassAnnotations方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parseController

 /**
  * Parse a controller class.
  *
  * @param string $class
  * @return array
  */
 public function parseController($class)
 {
     $reflectionClass = new ReflectionClass($class);
     $classAnnotations = $this->reader->getClassAnnotations($reflectionClass);
     $controllerMetadata = [];
     $middleware = [];
     // find entity parameters and plugins
     foreach ($classAnnotations as $annotation) {
         // controller attributes
         if ($annotation instanceof \ProAI\Annotations\Annotations\Controller) {
             $prefix = $annotation->prefix;
             $middleware = $this->addMiddleware($middleware, $annotation->middleware);
         }
         if ($annotation instanceof \ProAI\Annotations\Annotations\Middleware) {
             $middleware = $this->addMiddleware($middleware, $annotation->value);
         }
         // resource controller
         if ($annotation instanceof \ProAI\Annotations\Annotations\Resource) {
             $resourceMethods = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
             if (!empty($annotation->only)) {
                 $resourceMethods = array_intersect($resourceMethods, $annotation->only);
             } elseif (!empty($annotation->except)) {
                 $resourceMethods = array_diff($resourceMethods, $annotation->except);
             }
             $resource = ['name' => $annotation->value, 'methods' => $resourceMethods];
         }
     }
     // find routes
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $name = $reflectionMethod->getName();
         $methodAnnotations = $this->reader->getMethodAnnotations($reflectionMethod);
         $routeMetadata = [];
         // controller method is resource route
         if (!empty($resource) && in_array($name, $resource['methods'])) {
             $routeMetadata = ['uri' => $resource['name'] . $this->getResourcePath($name), 'controller' => $class, 'controllerMethod' => $name, 'httpMethod' => $this->getResourceHttpMethod($name), 'as' => $resource['name'] . '.' . $name, 'middleware' => ''];
         }
         // controller method is route
         if ($route = $this->hasHttpMethodAnnotation($name, $methodAnnotations)) {
             $routeMetadata = ['uri' => $route['uri'], 'controller' => $class, 'controllerMethod' => $name, 'httpMethod' => $route['httpMethod'], 'as' => $route['as'], 'middleware' => $route['middleware']];
         }
         // add more route options to route metadata
         if (!empty($routeMetadata)) {
             if (!empty($middleware)) {
                 $routeMetadata['middleware'] = $middleware;
             }
             // add other method annotations
             foreach ($methodAnnotations as $annotation) {
                 if ($annotation instanceof \ProAI\Annotations\Annotations\Middleware) {
                     $middleware = $this->addMiddleware($middleware, $routeMetadata['middleware']);
                 }
             }
             // add global prefix and middleware
             if (!empty($prefix)) {
                 $routeMetadata['uri'] = $prefix . '/' . $routeMetadata['uri'];
             }
             $controllerMetadata[$name] = $routeMetadata;
         }
     }
     return $controllerMetadata;
 }
開發者ID:proai,項目名稱:lumen-annotations,代碼行數:66,代碼來源:RouteScanner.php

示例2: getClassAnnotations

 /**
  * @param string|object $class
  * @return array
  */
 public function getClassAnnotations($class)
 {
     $reflectionClass = new \ReflectionClass($class);
     $classAnotation = array();
     foreach ($this->annotationReader->getClassAnnotations($reflectionClass) as $contraint) {
         if ($contraint instanceof Annotations\Synchronizer) {
             $classAnotation[] = $contraint;
         }
     }
     return $classAnotation;
 }
開發者ID:fezfez,項目名稱:keep-update,代碼行數:15,代碼來源:AnnotationDAO.php

示例3: loadClassMetadata

 /**
  * Parse all of the annotations for a given ClassMetadata object
  *
  * @param ClassMetadata $metadata
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $className = $reflClass->getName();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annotation) {
         if ($annotation instanceof XmlObject) {
             $this->loadClassAttributes($metadata);
             $this->loadClassElements($metadata);
             $this->loadClassLists($metadata);
             $this->loadClassValue($metadata);
         }
     }
 }
開發者ID:kustov-vitalik,項目名稱:xml-hitch,代碼行數:18,代碼來源:AnnotationLoader.php

示例4: getDefinitions

 /**
  * @param ReflectionClass $reflection
  * @return Definition[]|Generator
  */
 private function getDefinitions(ReflectionClass $reflection)
 {
     $annotations = $this->reader->getClassAnnotations($reflection);
     /** @var ServiceDefinition $builder */
     foreach ($annotations as $class => $annotation) {
         if (isset($this->builders[$class])) {
             $builder = $this->builders[$class];
         } else {
             /** @var string|Service $class */
             $this->builders[$class] = $builder = $class::getBuilder($this->reader);
         }
         list($id, $definition) = $builder->build($reflection, $annotation);
         (yield $id => $definition);
     }
 }
開發者ID:brainexe,項目名稱:annotations,代碼行數:19,代碼來源:Loader.php

示例5: loadMetadataForClass

 /**
  * @param ReflectionClass $class
  *
  * @return ClassMetadata
  */
 public function loadMetadataForClass(ReflectionClass $class)
 {
     $classMetadata = new ClassMetadata($class->getName());
     $classAnnotations = $this->reader->getClassAnnotations($class);
     foreach ($classAnnotations as $annotation) {
         if ($annotation instanceof Document) {
             $classMetadata->collection = $annotation->collection ?: strtolower($class->getShortName());
             $classMetadata->repository = $annotation->repository ?: DocumentRepository::class;
         }
     }
     $classMetadata->identifier = $this->findIdentifer($class);
     foreach ($class->getProperties() as $property) {
         $classMetadata->addPropertyMetadata($this->loadPropertyMetadata($property));
     }
     return $classMetadata;
 }
開發者ID:davidbadura,項目名稱:orangedb,代碼行數:21,代碼來源:AnnotationDriver.php

示例6: create

 /**
  * @param string $className
  * @return Datagrid
  */
 public function create($className)
 {
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $metadata = $entityManager->getClassMetadata($className);
     $reflection = $metadata->getReflectionClass();
     $datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
     $reader = new AnnotationReader();
     foreach ($reader->getClassAnnotations($reflection) as $annotation) {
         $params = compact('datagridSpec', 'annotation');
         $this->getEventManager()->trigger('discoverTitle', $this, $params);
     }
     foreach ($reflection->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'property');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     foreach ($reflection->getMethods() as $method) {
         foreach ($reader->getMethodAnnotations($method) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'method');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     $this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
     return $this->datagrids[$className];
 }
開發者ID:PoetikDragon,項目名稱:USCSS,代碼行數:31,代碼來源:DatagridManager.php

示例7: __construct

 /**
  * Entity Indexer
  * @param string|EntityClass $entityClassName
  *
  * @throws InvalidAnnotationException Invalid annotations used
  */
 public function __construct($entityClassName)
 {
     $this->entityClass = new \ReflectionClass($entityClassName);
     if (!$this->entityClass->isSubclassOf("\\SweetORM\\Entity")) {
         throw new \UnexpectedValueException("The className for getTable should be a class that is extending the SweetORM Entity class");
         // @codeCoverageIgnore
     }
     $this->entity = new EntityStructure();
     $this->entity->name = $this->entityClass->getName();
     // Reader
     $reader = new AnnotationReader();
     $this->classAnnotations = $reader->getClassAnnotations($this->entityClass);
     $this->entityAnnotation = $reader->getClassAnnotation($this->entityClass, EntityClass::class);
     // Validate Entity annotation
     if ($this->entityAnnotation === null || !$this->entityAnnotation instanceof EntityClass) {
         throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' should use Annotations to use it! Please look at the documentation for help.");
         // @codeCoverageIgnore
     }
     // Run all the indexers
     foreach (self::$indexers as $indexerClass) {
         $indexerFullClass = "\\SweetORM\\Structure\\Indexer\\" . $indexerClass;
         /** @var Indexer $instance */
         $instance = new $indexerFullClass($this->entityClass, $reader);
         $instance->indexEntity($this->entity);
     }
 }
開發者ID:tomvlk,項目名稱:sweet-orm,代碼行數:32,代碼來源:EntityIndexer.php

示例8: isTransient

    /**
     * Whether the class with the specified name is transient. Only non-transient
     * classes, that is entities and mapped superclasses, should have their metadata loaded.
     * A class is non-transient if it is annotated with either @Entity or
     * @MappedSuperclass in the class doc block.
     *
     * @param string $className
     * @return boolean
     */
    public function isTransient($className)
    {
        $classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));

        return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
               ! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
    }
開發者ID:nacef,項目名稱:doctrine2,代碼行數:16,代碼來源:AnnotationDriver.php

示例9: testParseAnnotationDocblocks

 public function testParseAnnotationDocblocks()
 {
     $class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Annotation');
     $reader = new AnnotationReader();
     $annots = $reader->getClassAnnotations($class);
     $this->assertEquals(0, count($annots));
 }
開發者ID:eltondias,項目名稱:Relogio,代碼行數:7,代碼來源:DCOM55Test.php

示例10: getContentFiles

 public function getContentFiles($object)
 {
     $reflectedClass = new \ReflectionClass($object);
     $reader = new AnnotationReader();
     $annotations = $reader->getClassAnnotations($reflectedClass);
     $isContentFiledClass = false;
     foreach ($annotations as $annotation) {
         if ($annotation instanceof ContentFiled) {
             $isContentFiledClass = true;
         }
     }
     if (!$isContentFiledClass) {
         throw new \InvalidArgumentException('Only @ContentFiled annotated classes are supported!');
     }
     $contentFiles = [];
     foreach ($reflectedClass->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof ContentFileAnnotation) {
                 $mappingType = $object->{$annotation->mappingTypeMethod}();
                 $contentFiles = array_merge($contentFiles, $this->contentFileManager->findFilesByMappingType($mappingType));
             }
         }
     }
     return $contentFiles;
 }
開發者ID:scigroup,項目名稱:tinyuplmngr,代碼行數:25,代碼來源:ContentFiledManager.php

示例11: getClassMetadata

 /**
  * @param string $classname
  * @return array
  */
 public function getClassMetadata($classname)
 {
     $classMetadata = [];
     $reflexionClass = $this->getReflectionClass($classname);
     $classAnnotations = $this->reader->getClassAnnotations($reflexionClass);
     foreach ($classAnnotations as $classAnnotation) {
         if (!isset($classMetadata[get_class($classAnnotation)])) {
             $classMetadata[get_class($classAnnotation)] = [];
         }
         $classMetadata[get_class($classAnnotation)][] = $classAnnotation;
     }
     if ($this->reader->getClassAnnotation($reflexionClass, ParentClass::class)) {
         $classMetadata = array_merge_recursive($this->getClassMetadata(get_parent_class($classname)), $classMetadata);
     }
     return $classMetadata;
 }
開發者ID:eoko,項目名稱:odm-metadata-annotation,代碼行數:20,代碼來源:AnnotationDriver.php

示例12: processClassAnnotations

 /**
  * @param ReflectionClass      $reflectionClass
  * @param ControllerCollection $controllerCollection
  */
 public function processClassAnnotations(ReflectionClass $reflectionClass, ControllerCollection $controllerCollection)
 {
     foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
         if ($annotation instanceof RouteAnnotation) {
             $annotation->process($controllerCollection);
         }
     }
 }
開發者ID:jsmith07,項目名稱:silex-annotation-provider,代碼行數:12,代碼來源:AnnotationService.php

示例13: loadClassAnnotations

 /**
  * @param AnnotationReader $reader
  * @param ReflectionClass $reflClass
  */
 protected function loadClassAnnotations(AnnotationReader $reader, ReflectionClass $reflClass)
 {
     foreach ($reader->getClassAnnotations($reflClass) as $annotation) {
         if ($annotation instanceof Prefix) {
             $this->metadata->setPrefix($annotation->value);
         }
     }
 }
開發者ID:tystr,項目名稱:redis-orm,代碼行數:12,代碼來源:AnnotationMetadataLoader.php

示例14: isTransient

    /**
     * Whether the class with the specified name is transient. Only non-transient
     * classes, that is entities and mapped superclasses, should have their metadata loaded.
     * A class is non-transient if it is annotated with either @Entity or
     * @MappedSuperclass in the class doc block.
     *
     * @param string $className
     * @return boolean
     */
    public function isTransient($className)
    {
        $classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className));

        return ! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\Document']) &&
               ! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\MappedSuperclass']) &&
               ! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\EmbeddedDocument']);
    }
開發者ID:nresni,項目名稱:symfony-sandbox,代碼行數:17,代碼來源:AnnotationDriver.php

示例15: testGivenAnObjectShouldProcessIt

 public function testGivenAnObjectShouldProcessIt()
 {
     a\AnnotationRegistry::registerFile(__DIR__ . "/resource/AnnotationSample.php");
     $someObj = new AnnotatedClass();
     $reader = new a\AnnotationReader("/tmp/", $debug = true);
     $classAnnots = $reader->getClassAnnotations(new ReflectionObject($someObj));
     $this->assertNotEmpty($classAnnots);
     $this->assertEquals($classAnnots[0]->property, "some");
 }
開發者ID:hvasoares,項目名稱:phplombok,代碼行數:9,代碼來源:DoctrineIntegrationTest.php


注:本文中的Doctrine\Common\Annotations\AnnotationReader::getClassAnnotations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。