当前位置: 首页>>代码示例>>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;未经允许,请勿转载。