当前位置: 首页>>代码示例>>PHP>>正文


PHP Reader::getClassAnnotations方法代码示例

本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getClassAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getClassAnnotations方法的具体用法?PHP Reader::getClassAnnotations怎么用?PHP Reader::getClassAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Annotations\Reader的用法示例。


在下文中一共展示了Reader::getClassAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadMetadataForClass

 /**
  * Load metadata class
  *
  * @param \ReflectionClass $class
  * @return ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $classMetadata = new ClassMetadata($class->name);
     $classMetadata->fileResources[] = $class->getFileName();
     foreach ($this->reader->getClassAnnotations($class) as $annotation) {
         if ($annotation instanceof NamespaceNode) {
             $classMetadata->addGraphNamespace($annotation);
         }
         if ($annotation instanceof GraphNode) {
             $classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value));
         }
     }
     foreach ($class->getProperties() as $property) {
         foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof GraphNode) {
                 $classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name));
             }
         }
     }
     foreach ($class->getMethods() as $method) {
         foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
             if ($annotation instanceof GraphNode) {
                 $classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name));
             }
         }
     }
     return $classMetadata;
 }
开发者ID:novaway,项目名称:open-graph,代码行数:34,代码来源:AnnotationDriver.php

示例2: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $object = new \ReflectionObject($controller[0]);
     $method = $object->getMethod($controller[1]);
     $classConfigurations = $this->reader->getClassAnnotations($object);
     $methodConfigurations = $this->reader->getMethodAnnotations($method);
     foreach (array_merge($classConfigurations, $methodConfigurations) as $configuration) {
         if ($configuration instanceof OAuth2) {
             $token = $this->token_storage->getToken();
             // If no access token is found by the firewall, then returns an authentication error
             if (!$token instanceof OAuth2Token) {
                 $this->createAuthenticationException($event, 'OAuth2 authentication required');
                 return;
             }
             foreach ($this->getCheckers() as $checker) {
                 $result = $checker->check($token, $configuration);
                 if (null !== $result) {
                     $this->createAccessDeniedException($event, $result);
                     return;
                 }
             }
         }
     }
 }
开发者ID:spomky-labs,项目名称:oauth2-server-bundle,代码行数:27,代码来源:AnnotationDriver.php

示例3: loadForClass

 /**
  * {@inheritDoc}
  */
 public function loadForClass($class, $group)
 {
     $reflectionClass = Reflection::loadClassReflection($class);
     $classAnnotations = $this->reader->getClassAnnotations($reflectionClass);
     $securityClassAnnotation = null;
     $rules = array();
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof ClassSecurityAnnotation && $group == $classAnnotation->group) {
             if ($securityClassAnnotation) {
                 throw new \RuntimeException(sprintf('The @ClassSecurity annotation already defined in class "%s".', $reflectionClass->getName()));
             }
             $securityClassAnnotation = $classAnnotation;
         }
         if ($rule = $this->transformAnnotationToRule($classAnnotation, $group, $class)) {
             $rules[] = $rule;
         }
     }
     if (!$securityClassAnnotation && !count($rules)) {
         return null;
     }
     if ($securityClassAnnotation) {
         $strategy = $securityClassAnnotation->strategy;
     } else {
         $strategy = Security::STRATEGY_AFFIRMATIVE;
     }
     $securityClass = new ClassSecurity($reflectionClass->getName(), $strategy, $rules, $group);
     return $securityClass;
 }
开发者ID:Gtvar,项目名称:FivePercent-ObjectSecurity,代码行数:31,代码来源:AnnotationLoader.php

示例4: onPostSerialize

 public function onPostSerialize(ObjectEvent $event)
 {
     /**
      * @var JsonSerializationVisitor $visitor
      */
     $visitor = $event->getVisitor();
     $object = $event->getObject();
     $annotations = $this->annotationReader->getClassAnnotations(new \ReflectionObject($object));
     $links = array();
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Link) {
             if ($annotation->url) {
                 $uri = $this->evaluate($annotation->url, $object);
             } else {
                 $uri = $this->router->generate($annotation->route, $this->resolveParams($annotation->params, $object));
             }
             // allow a blank URI to be an optional link
             if ($uri) {
                 $links[$annotation->name] = $uri;
             }
         }
     }
     if ($links) {
         $visitor->addData('_links', $links);
     }
 }
开发者ID:C3-TKO,项目名称:smash-api,代码行数:26,代码来源:LinkSerializationSubscriber.php

示例5: onConfigureRoute

 /**
  * Reads the "@Access" annotations from the controller stores them in the "access" route option.
  */
 public function onConfigureRoute($event, $route)
 {
     if (!$this->reader) {
         $this->reader = new SimpleAnnotationReader();
         $this->reader->addNamespace('Pagekit\\User\\Annotation');
     }
     if (!$route->getControllerClass()) {
         return;
     }
     $access = [];
     foreach (array_merge($this->reader->getClassAnnotations($route->getControllerClass()), $this->reader->getMethodAnnotations($route->getControllerMethod())) as $annot) {
         if (!$annot instanceof Access) {
             continue;
         }
         if ($expression = $annot->getExpression()) {
             $access[] = $expression;
         }
         if ($admin = $annot->getAdmin() !== null) {
             $route->setPath('admin' . rtrim($route->getPath(), '/'));
             $permission = 'system: access admin area';
             if ($admin) {
                 $access[] = $permission;
             } else {
                 if ($key = array_search($permission, $access)) {
                     unset($access[$key]);
                 }
             }
         }
     }
     if ($access) {
         $route->setDefault('_access', array_unique($access));
     }
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:36,代码来源:AccessListener.php

示例6: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $annotations = $this->reader->getClassAnnotations($class);
     if (0 === count($annotations)) {
         return null;
     }
     $classMetadata = new ClassMetadata($class->getName());
     $classMetadata->fileResources[] = $class->getFileName();
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Annotation\Resource) {
             // auto transform type from class name
             if (!$annotation->type) {
                 $annotation->type = String::dasherize($class->getShortName());
             }
             $classMetadata->setResource(new Resource($annotation->type, $annotation->showLinkSelf));
         }
     }
     $classProperties = $class->getProperties();
     foreach ($classProperties as $property) {
         $annotations = $this->reader->getPropertyAnnotations($property);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Annotation\Id) {
                 $classMetadata->setIdField($property->getName());
             } else {
                 if ($annotation instanceof Annotation\Relationship) {
                     $classMetadata->addRelationship(new Relationship($property->getName(), $annotation->includeByDefault, $annotation->showLinkSelf, $annotation->showLinkRelated));
                 }
             }
         }
     }
     return $classMetadata;
 }
开发者ID:aliebing,项目名称:JsonApiBundle,代码行数:35,代码来源:AnnotationDriver.php

示例7: onFilterController

 public function onFilterController(FilterControllerEvent $event)
 {
     list($object, $method) = $event->getController();
     // the controller could be a proxy
     $className = ClassUtils::getClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $allControllerAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
     $allMethodAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
     $guardAnnotationsFilter = function ($annotation) {
         return $annotation instanceof Guard;
     };
     $controllerGuardAnnotations = array_filter($allControllerAnnotations, $guardAnnotationsFilter);
     $methodGuardAnnotations = array_filter($allMethodAnnotations, $guardAnnotationsFilter);
     $guardAnnotations = array_merge($controllerGuardAnnotations, $methodGuardAnnotations);
     $permissions = [];
     foreach ($guardAnnotations as $guardAnnotation) {
         $value = $guardAnnotation->value;
         if (!is_array($value)) {
             $value = [$value];
         }
         $permissions = array_merge($value, $permissions);
     }
     $permissions = array_unique($permissions);
     if (!empty($permissions) && !$this->security->isGranted($permissions)) {
         $e = new PermissionRequiredException();
         $e->setRequiredPermissions($permissions)->setCurrentPermissions($this->security->getToken()->getUser()->getPermissions());
         throw $e;
     }
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:30,代码来源:ControllerListener.php

示例8: getClassAnnotations

 /**
  * Get Annotations for class
  *
  * @param \ReflectionClass $class
  * @return array
  */
 public function getClassAnnotations(\ReflectionClass $class)
 {
     $annotations = array();
     foreach ($this->delegate->getClassAnnotations($class) as $annot) {
         $annotations[get_class($annot)] = $annot;
     }
     return $annotations;
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:14,代码来源:IndexedReader.php

示例9: isClassInjected

 /**
  * {@inheritdoc}
  */
 public function isClassInjected(\ReflectionClass $class)
 {
     foreach ($this->reader->getClassAnnotations($class) as $annotation) {
         if ($annotation instanceof Inject) {
             return true;
         }
     }
     return false;
 }
开发者ID:brick,项目名称:di,代码行数:12,代码来源:AnnotationPolicy.php

示例10: getTransformAnnotations

 /**
  * Annotations specifically related to Entity Transformation as defined in the TransformMapping class
  *
  * @param $class
  * @return null | TransformMapping
  */
 public function getTransformAnnotations($class)
 {
     $annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
     foreach ($annotations as $annotation) {
         if ($annotation instanceof TransformMapping) {
             return $annotation;
         }
     }
     return null;
 }
开发者ID:swimson,项目名称:poncho,代码行数:16,代码来源:AnnotationReader.php

示例11: isTracked

 /**
  * Get the annotation from a class or null if it doesn't exists.
  *
  * @param EntityManagerInterface $em
  * @param mixed                  $entity
  * @return bool
  */
 public function isTracked(EntityManagerInterface $em, $entity)
 {
     $class = get_class($entity);
     $annotations = $this->reader->getClassAnnotations($em->getClassMetadata($class)->getReflectionClass());
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Tracked) {
             return true;
         }
     }
     return false;
 }
开发者ID:hostnet,项目名称:entity-tracker-component,代码行数:18,代码来源:EntityAnnotationMetadataProvider.php

示例12: getObjectMappingAnnotation

 /**
  * Get object mapping annotation for class
  *
  * @param \ReflectionClass $refClass
  * @param string           $group
  *
  * @return Object|null
  */
 private function getObjectMappingAnnotation(\ReflectionClass $refClass, $group)
 {
     $classAnnotations = $this->reader->getClassAnnotations($refClass);
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof Object) {
             if ($classAnnotation->group == $group) {
                 return $classAnnotation;
             }
         }
     }
     return null;
 }
开发者ID:Gtvar,项目名称:FivePercent-ObjectMapper,代码行数:20,代码来源:AnnotationLoader.php

示例13: getClassAnnotations

 /**
  * {@inheritDoc}
  */
 public function getClassAnnotations(\ReflectionClass $class)
 {
     $cacheKey = $class->getName();
     if (isset($this->loadedAnnotations[$cacheKey])) {
         return $this->loadedAnnotations[$cacheKey];
     }
     if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
         $annots = $this->delegate->getClassAnnotations($class);
         $this->saveToCache($cacheKey, $annots);
     }
     return $this->loadedAnnotations[$cacheKey] = $annots;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:15,代码来源:CachedReader.php

示例14: getProxyAnnotations

 /**
  * Annotations specifically related to Entity Transformation as defined in the Proxy class
  *
  * @param $class
  * @return null | Proxy
  */
 public function getProxyAnnotations($class)
 {
     if ($this->doctrineProxyResolver->isDoctrineProxy($class)) {
         $class = $this->doctrineProxyResolver->unwrapDoctrineProxyClass($class);
     }
     $annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Proxy) {
             return $annotation;
         }
     }
     return null;
 }
开发者ID:mindgruve,项目名称:gordo-proxy,代码行数:19,代码来源:AnnotationReader.php

示例15: onKernelController

 /**
  * Modifies the Request object to apply configuration information found in
  * controllers annotations like the template to render or HTTP caching
  * configuration.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $object = new \ReflectionObject($controller[0]);
     $method = $object->getMethod($controller[1]);
     $request = $event->getRequest();
     foreach (array_merge($this->reader->getClassAnnotations($object), $this->reader->getMethodAnnotations($method)) as $configuration) {
         if ($configuration instanceof ConfigurationInterface) {
             $request->attributes->set('_' . $configuration->getAliasName(), $configuration);
         }
     }
 }
开发者ID:laubosslink,项目名称:lab,代码行数:21,代码来源:ControllerListener.php


注:本文中的Doctrine\Common\Annotations\Reader::getClassAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。