Doctrine\Common\Annotations\AnnotationReader::getMethodAnnotations PHP Méthode

getMethodAnnotations() public méthode

{@inheritDoc}
public getMethodAnnotations ( ReflectionMethod $method )
$method ReflectionMethod
    public function getMethodAnnotations(ReflectionMethod $method)
    {
        $class = $method->getDeclaringClass();
        $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
        $this->parser->setTarget(Target::TARGET_METHOD);
        $this->parser->setImports($this->getMethodImports($method));
        $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
        $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
        return $this->parser->parse($method->getDocComment(), $context);
    }

Usage Example

 /**
  * {@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);
 }
All Usage Examples Of Doctrine\Common\Annotations\AnnotationReader::getMethodAnnotations