Doctrine\Common\Annotations\CachedReader::getMethodAnnotation PHP Method

getMethodAnnotation() public method

{@inheritDoc}
public getMethodAnnotation ( ReflectionMethod $method, $annotationName )
$method ReflectionMethod
    public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
    {
        foreach ($this->getMethodAnnotations($method) as $annot) {
            if ($annot instanceof $annotationName) {
                return $annot;
            }
        }
        return null;
    }

Usage Example

 /**
  * @param IApiMethod $method
  * @param string $actionName
  * @return string
  * @throws DublicateActionException
  * @throws ActionNotFoundException
  */
 public function getClassMethodNameByMethodAndActionName(IApiMethod $method, $actionName)
 {
     $refClass = new \ReflectionClass(get_class($method));
     $classMethods = $refClass->getMethods();
     $classAction = null;
     foreach ($classMethods as $classMethod) {
         $annotationAction = $this->annotationReader->getMethodAnnotation($classMethod, '\\TSCore\\JsonRpcServerBundle\\Method\\Annotation\\Action');
         if ($annotationAction instanceof Action) {
             if ($annotationAction->getName() === $actionName && $classAction !== null) {
                 throw new DublicateActionException(sprintf("Action name %s dublicate in method %s", $actionName, get_class($method)));
             }
             if ($annotationAction->getName() === $actionName && $classAction === null) {
                 $classAction = $classMethod->getName();
             }
         }
     }
     if (null === $classAction) {
         throw new ActionNotFoundException(sprintf('Action %s not found in method %s!', $actionName, get_class($method)));
     }
     return $classAction;
 }