Example #1
0
 /**
  * Reads all supported method annotations.
  *
  * @param stirng            $className
  * @param \ReflectionMethod $method
  *
  * @return array
  */
 private function readMethodAnnotations($className, \ReflectionMethod $method)
 {
     $annotations = array();
     // Read parent annotations.
     try {
         $prototype = $method->getPrototype();
         $annotations = array_merge($annotations, $this->readMethodAnnotations($className, $prototype));
     } catch (\ReflectionException $e) {
     }
     // Read method annotations.
     if ($docBlock = $method->getDocComment()) {
         $description = NULL;
         foreach (explode("\n", $docBlock) as $docLine) {
             $docLine = preg_replace('/^\\/\\*\\*\\s*|^\\s*\\*\\s*|\\s*\\*\\/$|\\s*$/', '', $docLine);
             if (preg_match('/^\\@(' . $this->availableAnnotations . ')\\s*(.*)?$/i', $docLine, $matches)) {
                 $class = $this->annotationClasses[strtolower($matches[1])];
                 $callback = array($className, $method->getName());
                 if (isset($matches[2]) && !empty($matches[2])) {
                     $annotation = new $class($callback, $matches[2]);
                 } else {
                     $annotation = new $class($callback);
                 }
                 if (NULL !== $description) {
                     $annotation->setDescription($description);
                 }
                 $annotations[] = $annotation;
             } elseif (NULL === $description && '' !== $docLine && FALSE === strpos($docLine, '@')) {
                 $description = $docLine;
             }
         }
     }
     return $annotations;
 }
Example #2
0
 /**
  * Gets the method prototype (if there is one).
  *
  * @return A `ReflectionMethod` instance of the method prototype.
  * @throws ReflectionException if the method does not have a prototype.
  */
 public function getPrototype()
 {
     /* @var \ReflectionMethod $prototype */
     /* @var \ReflectionClass $class */
     $prototype = parent::getPrototype();
     $class = $prototype->getDeclaringClass();
     return new self($class->getName(), $prototype->getName());
 }
Example #3
0
 /**
  * Returns the prototype.
  *
  * This is mostly a wrapper method, which calls the corresponding method of
  * the parent class. The only difference is that it returns an instance
  * ezcReflectionClass instead of a ReflectionClass instance
  * @return ezcReflectionClass Prototype
  * @throws ReflectionException if the method has no prototype
  */
 public function getPrototype()
 {
     if ($this->reflectionSource instanceof parent) {
         $prototype = $this->reflectionSource->getPrototype();
     } else {
         $prototype = parent::getPrototype();
     }
     return new ezcReflectionClass($prototype->getName());
 }
 /**
  * Reads all supported method annotations.
  *
  * @param string            $className
  * @param \ReflectionMethod $method
  *
  * @return array
  */
 private function readMethodAnnotations($className, \ReflectionMethod $method)
 {
     $annotations = array();
     // read parent annotations
     try {
         $prototype = $method->getPrototype();
         // error occurs on PHP 5.4.11+ when the same trait is used by a parent and the child class
         if ($prototype->getDeclaringClass()->getName() !== $method->getDeclaringClass()->getName()) {
             $annotations = array_merge($annotations, $this->readMethodAnnotations($className, $prototype));
         }
     } catch (\ReflectionException $e) {
     }
     // read method annotations
     if ($docBlock = $method->getDocComment()) {
         $description = null;
         foreach (explode("\n", $docBlock) as $docLine) {
             $docLine = preg_replace('/^\\/\\*\\*\\s*|^\\s*\\*\\s*|\\s*\\*\\/$|\\s*$/', '', $docLine);
             if (preg_match('/^\\@(' . $this->availableAnnotations . ')\\s*(.*)?$/i', $docLine, $matches)) {
                 $class = $this->annotationClasses[strtolower($matches[1])];
                 $callback = array($className, $method->getName());
                 if (isset($matches[2]) && !empty($matches[2])) {
                     $annotation = new $class($callback, $matches[2]);
                 } else {
                     $annotation = new $class($callback);
                 }
                 if (null !== $description) {
                     $annotation->setDescription($description);
                 }
                 $annotations[] = $annotation;
             } elseif (null === $description && '' !== $docLine && false === strpos($docLine, '@')) {
                 $description = $docLine;
             }
         }
     }
     return $annotations;
 }
Example #5
0
 /**
  * @return Method
  */
 public function getPrototype()
 {
     $prototype = parent::getPrototype();
     return new Method($prototype->getDeclaringClass()->getName(), $prototype->getName());
 }
 /**
  * @param \ReflectionMethod $reflectionMethod
  * @return DocBlock
  */
 protected function getInheritDoc($reflectionMethod)
 {
     $parentClass = $reflectionMethod->getDeclaringClass()->getParentClass();
     //Get either a parent or the interface
     if ($parentClass) {
         $method = $parentClass->getMethod($reflectionMethod->getName());
     } else {
         $method = $reflectionMethod->getPrototype();
     }
     if ($method) {
         $namespace = $method->getDeclaringClass()->getNamespaceName();
         $phpdoc = new DocBlock($method, new Context($namespace));
         if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
             //Not at the end yet, try another parent/interface..
             return $this->getInheritDoc($method);
         } else {
             return $phpdoc;
         }
     }
 }
Example #7
0
 function getPrototype()
 {
     $prototype = parent::getPrototype();
     return new NMethodReflection($prototype->getDeclaringClass()->getName(), $prototype->getName());
 }
 /**
  * Returns the method prototype.
  *
  * @return \TokenReflection\Php\ReflectionMethod
  */
 public function getPrototype()
 {
     return self::create(parent::getPrototype(), $this->broker);
 }
 /**
  * Returns whether the method is implement method.
  *
  * @param \ReflectionMethod $method          ReflectionMethod object.
  * @param \ReflectionClass  &$declaringClass Output parameter for Declaring class.
  * @return bool true if the method is implement method, false otherwise.
  */
 protected function isImplementMethod(\ReflectionMethod $method, &$declaringClass)
 {
     try {
         $declaringClass = $method->getPrototype()->getDeclaringClass();
         if ($declaringClass->isInterface()) {
             return true;
         }
         if ($declaringClass->getMethod($method->getName())->isAbstract()) {
             return true;
         }
         return false;
     } catch (\ReflectionException $e) {
         return null;
     }
 }