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


PHP AnnotationReader::getMethodAnnotations方法代码示例

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


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

示例1: generate

 /**
  * {@inheritdoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $classGenerator->setExtendedClass($originalClass->getName());
     $additionalInterfaces = ['OpenClassrooms\\ServiceProxy\\ServiceProxyInterface'];
     $additionalProperties['proxy_realSubject'] = new PropertyGenerator('proxy_realSubject', null, PropertyGenerator::FLAG_PRIVATE);
     $additionalMethods['setProxy_realSubject'] = new MethodGenerator('setProxy_realSubject', [['name' => 'realSubject']], MethodGenerator::FLAG_PUBLIC, '$this->proxy_realSubject = $realSubject;');
     $methods = $originalClass->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         $preSource = '';
         $postSource = '';
         $exceptionSource = '';
         $methodAnnotations = $this->annotationReader->getMethodAnnotations($method);
         foreach ($methodAnnotations as $methodAnnotation) {
             if ($methodAnnotation instanceof Cache) {
                 $this->addCacheAnnotation($classGenerator);
                 $additionalInterfaces['cache'] = 'OpenClassrooms\\ServiceProxy\\ServiceProxyCacheInterface';
                 $response = $this->cacheStrategy->execute($this->serviceProxyStrategyRequestBuilder->create()->withAnnotation($methodAnnotation)->withClass($originalClass)->withMethod($method)->build());
                 foreach ($response->getMethods() as $methodToAdd) {
                     $additionalMethods[$methodToAdd->getName()] = $methodToAdd;
                 }
                 foreach ($response->getProperties() as $propertyToAdd) {
                     $additionalProperties[$propertyToAdd->getName()] = $propertyToAdd;
                 }
                 $preSource .= $response->getPreSource();
                 $postSource .= $response->getPostSource();
                 $exceptionSource .= $response->getExceptionSource();
             }
         }
         $classGenerator->addMethodFromGenerator($this->generateProxyMethod($method, $preSource, $postSource, $exceptionSource));
     }
     $classGenerator->setImplementedInterfaces($additionalInterfaces);
     $classGenerator->addProperties($additionalProperties);
     $classGenerator->addMethods($additionalMethods);
 }
开发者ID:OpenClassrooms,项目名称:ServiceProxy,代码行数:38,代码来源:ServiceProxyGenerator.php

示例2: loadMetadataForClass

 /**
  * @param \ReflectionClass $class
  *
  * @return \Metadata\ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $classMetadata = new ClassMetadata($class->getName());
     foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         if (false === strpos($reflectionMethod->getName(), 'Action')) {
             continue;
         }
         if ($reflectionMethod->isAbstract()) {
             continue;
         }
         $methodMetadata = new ActionMetadata($class->getName(), $reflectionMethod->getName());
         $annotations = $this->reader->getMethodAnnotations($reflectionMethod);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof \BackBee\Rest\Controller\Annotations\QueryParam) {
                 $data = array('name' => $annotation->name, 'key' => $annotation->key ? $annotation->key : $annotation->name, 'default' => $annotation->default, 'description' => $annotation->description, 'requirements' => $annotation->requirements);
                 $methodMetadata->queryParams[] = $data;
             } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\RequestParam) {
                 $data = array('name' => $annotation->name, 'key' => $annotation->key ? $annotation->key : $annotation->name, 'default' => $annotation->default, 'description' => $annotation->description, 'requirements' => $annotation->requirements);
                 $methodMetadata->requestParams[] = $data;
             } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\Pagination) {
                 $methodMetadata->default_start = $annotation->default_start;
                 $methodMetadata->default_count = $annotation->default_count;
                 $methodMetadata->max_count = $annotation->max_count;
                 $methodMetadata->min_count = $annotation->min_count;
             } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\ParamConverter) {
                 $methodMetadata->param_converter_bag[] = $annotation;
             } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\Security) {
                 $methodMetadata->security[] = $annotation;
             }
         }
         $classMetadata->addMethodMetadata($methodMetadata);
     }
     return $classMetadata;
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:39,代码来源:AnnotationDriver.php

示例3: 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

示例4: testAnnotationReader

 public function testAnnotationReader()
 {
     $reader = new AnnotationReader();
     $method = new \ReflectionMethod('FOS\\RestBundle\\Tests\\Fixtures\\Controller\\ParamsAnnotatedController', 'getArticlesAction');
     $params = $reader->getMethodAnnotations($method);
     // Param 1 (query)
     $this->assertEquals('page', $params[0]->name);
     $this->assertEquals('\\d+', $params[0]->requirements);
     $this->assertEquals('1', $params[0]->default);
     $this->assertEquals('Page of the overview.', $params[0]->description);
     $this->assertFalse($params[0]->map);
     $this->assertFalse($params[0]->strict);
     // Param 2 (request)
     $this->assertEquals('byauthor', $params[1]->name);
     $this->assertEquals('[a-z]+', $params[1]->requirements);
     $this->assertEquals('by author', $params[1]->description);
     $this->assertEquals(['search'], $params[1]->incompatibles);
     $this->assertFalse($params[1]->map);
     $this->assertTrue($params[1]->strict);
     // Param 3 (query)
     $this->assertEquals('filters', $params[2]->name);
     $this->assertTrue($params[2]->map);
     $this->assertEquals(new NotNull(), $params[2]->requirements);
     // Param 4 (file)
     $this->assertEquals('avatar', $params[3]->name);
     $this->assertEquals(['mimeTypes' => 'application/json'], $params[3]->requirements);
     $this->assertTrue($params[3]->image);
     $this->assertTrue($params[3]->strict);
     // Param 5 (file)
     $this->assertEquals('foo', $params[4]->name);
     $this->assertEquals(new NotNull(), $params[4]->requirements);
     $this->assertFalse($params[4]->image);
     $this->assertFalse($params[4]->strict);
 }
开发者ID:francescolaffi,项目名称:FOSRestBundle,代码行数:34,代码来源:ParamReaderTest.php

示例5: processMethods

 /**
  * Process the method
  * @param $methods
  * @param Mapping\ClassMetaData $metadata
  * @throws DrestException
  */
 protected function processMethods($methods, Mapping\ClassMetaData $metadata)
 {
     // Set the handle calls
     foreach ($methods as $method) {
         /* @var \ReflectionMethod $method */
         if ($method->isPublic()) {
             foreach ($this->reader->getMethodAnnotations($method) as $methodAnnotation) {
                 if ($methodAnnotation instanceof Annotation\Handle) {
                     // Make sure the for is not empty
                     if (empty($methodAnnotation->for) || !is_string($methodAnnotation->for)) {
                         throw DrestException::handleForCannotBeEmpty();
                     }
                     if (($routeMetaData = $metadata->getRouteMetaData($methodAnnotation->for)) === false) {
                         throw DrestException::handleAnnotationDoesntMatchRouteName($methodAnnotation->for);
                     }
                     if ($routeMetaData->hasHandleCall()) {
                         // There is already a handle set for this route
                         throw DrestException::handleAlreadyDefinedForRoute($routeMetaData);
                     }
                     $routeMetaData->setHandleCall($method->getName());
                 }
             }
         }
     }
 }
开发者ID:ptheberge,项目名称:drest,代码行数:31,代码来源:AnnotationDriver.php

示例6: getMethodCallbacks

 /**
  * Returns an array of callbacks for lifecycle annotations on the given method.
  *
  * @param \ReflectionMethod $method
  * @return array
  */
 protected function getMethodCallbacks(\ReflectionMethod $method)
 {
     $callbacks = array();
     $annotations = $this->reader->getMethodAnnotations($method);
     foreach ($annotations as $annotation) {
         if ($annotation instanceof \Doctrine\ORM\Mapping\PrePersist) {
             $callbacks[] = array($method->name, Events::prePersist);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PostPersist) {
             $callbacks[] = array($method->name, Events::postPersist);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PreUpdate) {
             $callbacks[] = array($method->name, Events::preUpdate);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PostUpdate) {
             $callbacks[] = array($method->name, Events::postUpdate);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PreRemove) {
             $callbacks[] = array($method->name, Events::preRemove);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PostRemove) {
             $callbacks[] = array($method->name, Events::postRemove);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PostLoad) {
             $callbacks[] = array($method->name, Events::postLoad);
         }
         if ($annotation instanceof \Doctrine\ORM\Mapping\PreFlush) {
             $callbacks[] = array($method->name, Events::preFlush);
         }
     }
     return $callbacks;
 }
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:38,代码来源:FlowAnnotationDriver.php

示例7: getMaxQueryAnnotation

 private function getMaxQueryAnnotation()
 {
     foreach (debug_backtrace() as $step) {
         if ('test' === substr($step['function'], 0, 4)) {
             //TODO: handle tests with the @test annotation
             $annotations = $this->annotationReader->getMethodAnnotations(new \ReflectionMethod($step['class'], $step['function']));
             foreach ($annotations as $annotationClass) {
                 if ($annotationClass instanceof QueryCount && isset($annotationClass->maxQueries)) {
                     /* @var $annotations \Liip\FunctionalTestBundle\Annotations\QueryCount */
                     return $annotationClass->maxQueries;
                 }
             }
         }
     }
     return false;
 }
开发者ID:ericpoe,项目名称:LiipFunctionalTestBundle,代码行数:16,代码来源:QueryCounter.php

示例8: testBasicClassAnnotations

 /**
  * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonAnySetter
  */
 public function testBasicClassAnnotations()
 {
     AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonAnySetter.php');
     $annotationReader = new AnnotationReader();
     $got = $annotationReader->getMethodAnnotations(new \ReflectionMethod(__NAMESPACE__ . '\\JsonAnySetterTestVictim', 'basic'));
     $this->assertEquals(array(new JsonAnySetter()), $got);
 }
开发者ID:siad007,项目名称:php-weasel,代码行数:10,代码来源:JsonAnySetterTest.php

示例9: getMethodAnnotations

    public function getMethodAnnotations(\ReflectionMethod $method)
    {
        $this->setAutoloadAnnotations(true);
        $this->setAnnotationCreationFunction(function ($name, $values)
        {
            $r = new \ReflectionClass($name);
            if (!$r->implementsInterface('Bundle\\Sensio\\FrameworkExtraBundle\\Configuration\\ConfigurationInterface')) {
                return null;
            }

            $configuration = new $name();
            foreach ($values as $key => $value) {
                if (!method_exists($configuration, $method = 'set'.$key)) {
                    throw new \BadMethodCallException(sprintf("Unknown annotation attribute '%s' for '%s'.", ucfirst($key), get_class($this)));
                }
                $configuration->$method($value);
            }

            return $configuration;
        });

        $this->setDefaultAnnotationNamespace('Bundle\\Sensio\\FrameworkExtraBundle\\Configuration\\');
        $configurations = parent::getMethodAnnotations($method);
        $this->setAnnotationCreationFunction(function ($name, $values) { return null; });

        return $configurations;
    }
开发者ID:ruudk,项目名称:FrameworkExtraBundle,代码行数:27,代码来源:AnnotationReader.php

示例10: __construct

 public function __construct($consumerWorker, ConnectionFactory $connectionFactory)
 {
     $this->connectionFactory = $connectionFactory;
     $className = get_class($consumerWorker);
     $reflectionClass = new \ReflectionClass($className);
     $reader = new AnnotationReader();
     $methods = $reflectionClass->getMethods();
     foreach ($methods as $method) {
         $methodAnnotations = $reader->getMethodAnnotations($method);
         foreach ($methodAnnotations as $annotation) {
             if ($annotation instanceof Annotation\Consumer) {
                 $parameters = $method->getParameters();
                 $taskClassName = false;
                 if (!empty($parameters)) {
                     $taskClass = $parameters[0]->getClass();
                     $isMessage = $taskClass->implementsInterface('IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
                     if (!$isMessage) {
                         throw new \InvalidArgumentException('Task must implmenet IvixLabs\\RabbitmqBundle\\Message\\MessageInterface');
                     }
                     $taskClassName = $taskClass->getName();
                 }
                 $key = $annotation->connectionName . '_' . $annotation->channelName . '_' . $annotation->exchangeName . '_' . $annotation->routingKey;
                 if (!isset($this->taskClasses[$key])) {
                     $this->taskClasses[$key] = [];
                 }
                 $this->taskClasses[$key][] = [$taskClassName, $method->getClosure($consumerWorker), $annotation];
             }
         }
     }
 }
开发者ID:IvixLabs,项目名称:RabbitmqBundle,代码行数:30,代码来源:Consumer.php

示例11: testConstructorClassAnnotations

 /**
  * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonCreator
  * @covers \Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonProperty
  */
 public function testConstructorClassAnnotations()
 {
     AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonCreator.php');
     AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Weasel/JsonMarshaller/Config/DoctrineAnnotations/JsonProperty.php');
     $annotationReader = new AnnotationReader();
     $got = $annotationReader->getMethodAnnotations(new \ReflectionMethod(__NAMESPACE__ . '\\JsonCreatorTestVictim', '__construct'));
     $this->assertEquals(array(new JsonCreator(array("params" => array(new JsonProperty(array("name" => "foo", "type" => "int")), new JsonProperty(array("name" => "bar", "type" => "int")))))), $got);
 }
开发者ID:siad007,项目名称:php-weasel,代码行数:12,代码来源:JsonCreatorTest.php

示例12: __construct

 /**
  * Constructor
  *
  * @param IReflectionMethod $method
  */
 public function __construct(IReflectionMethod $method)
 {
     parent::__construct($method);
     $methodName = $this->reflection->getName();
     $reader = new AnnotationReader();
     $this->doctrineAnnotations = $reader->getMethodAnnotations(new \ReflectionMethod($this->reflection->getDeclaringClassName(), $methodName));
     list($this->name, $this->httpMethod) = $this->processMethodName($methodName);
     $this->processAnnotations();
 }
开发者ID:patgod85,项目名称:phpdoc2rst,代码行数:14,代码来源:MethodElement.php

示例13: connect

 /**
  * @param Application $app
  * @return \Silex\ControllerCollection
  */
 public function connect(Application $app)
 {
     /** @var \Silex\ControllerCollection $controllers */
     $controllers = $app['controllers_factory'];
     // Routes are already cached using Flint
     if (file_exists($app['sys_temp_path'] . 'ProjectUrlMatcher.php')) {
         return $controllers;
     }
     $reflection = new \ReflectionClass($app[$this->controllerName]);
     $className = $reflection->getName();
     // Needed in order to get annotations
     $annotationReader = new AnnotationReader();
     //$classAnnotations = $annotationReader->getClassAnnotations($reflection);
     $routeAnnotation = new Route(array());
     $methodAnnotation = new Method(array());
     $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         $methodName = $method->getName();
         $controllerName = $this->controllerName . ':' . $methodName;
         // Parse only function with the "Action" suffix
         if (strpos($methodName, 'Action') === false) {
             continue;
         }
         // Getting all annotations
         $routeObjects = $annotationReader->getMethodAnnotations($method);
         /** @var Method $routeObject */
         $methodObject = $annotationReader->getMethodAnnotation($method, $methodAnnotation);
         $methodsToString = 'GET';
         if ($methodObject) {
             $methodsToString = implode('|', $methodObject->getMethods());
         }
         /** @var Route $routeObject */
         foreach ($routeObjects as $routeObject) {
             if ($routeObject && is_a($routeObject, 'Symfony\\Component\\Routing\\Annotation\\Route')) {
                 $match = $controllers->match($routeObject->getPath(), $controllerName, $methodsToString);
                 // Setting requirements
                 $req = $routeObject->getRequirements();
                 if (!empty($req)) {
                     foreach ($req as $key => $value) {
                         $match->assert($key, $value);
                     }
                 }
                 // Setting defaults
                 $defaults = $routeObject->getDefaults();
                 if (!empty($defaults)) {
                     foreach ($defaults as $key => $value) {
                         $match->value($key, $value);
                     }
                 }
                 $match->bind($controllerName);
             }
         }
     }
     return $controllers;
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:59,代码来源:ReflectionControllerProvider.php

示例14: testReadPerformance

 /**
  * @group performance
  */
 public function testReadPerformance()
 {
     $method = $this->getMethod();
     $time = microtime(true);
     for ($i = 0, $c = 150; $i < $c; $i++) {
         $reader = new AnnotationReader();
         $reader->getMethodAnnotations($method);
     }
     $time = microtime(true) - $time;
     $this->printResults('reader', $time, $c);
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:14,代码来源:PerformanceTest.php

示例15: onKernelController

 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $annotationReader = new AnnotationReader();
     $reflectionClass = new \ReflectionClass($controller[0]);
     $reflectionMethod = $reflectionClass->getMethod($controller[1]);
     $annotations = $annotationReader->getMethodAnnotations($reflectionMethod);
     foreach ($annotations as $annotation) {
         if ($this->supports($annotation)) {
             $this->parseAnnotation($reflectionMethod, $annotation, $request);
         }
     }
 }
开发者ID:javihgil,项目名称:doctrine-pagination-bundle,代码行数:17,代码来源:PaginationParamConverterListener.php


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