protected function doParsing($string)
 {
     $stream = new StringStream($string);
     $annotations = array();
     while ($char = $stream->getFirstCharacter()) {
         if ($char == '@') {
             $parser = new AnnotationParser();
             $annotation = $parser->parseStream($stream);
             $annotations[get_class($annotation)] = $annotation;
         } else {
             $stream->forward();
         }
     }
     return $annotations;
 }
 /**
  * Constructor
  *
  * @param mixed $class Classname or object (object of the class) that contains the method.
  * @param string $name Name of the method
  * @access public
  * @return void
  */
 public function __construct($class, $name)
 {
     parent::__construct($class, $name);
     // get the annotations
     $parser = new AnnotationParser($this->getDocComment());
     $this->annotations = $parser->getAnnotationArray();
 }
Beispiel #3
0
 public function testParseHome()
 {
     $homeanno = AnnotationParser::parse($this->homeAnno);
     foreach ($homeanno as $name => &$params) {
         $params = array_map(function ($p) {
             return $p ? $p() : null;
         }, $params);
     }
     $this->assertEquals(['get' => [['/path']], 'auth' => [null], 'bad' => [[]]], $homeanno);
 }
 /**
  *
  *
  * @param string $docBlock
  * @return Annotation[]
  * @throws \InvalidArgumentException
  */
 public function parse($docBlock)
 {
     $this->init($docBlock);
     $lines = preg_split('/[\\r\\n|\\r|\\n]/', $docBlock, null, \PREG_SPLIT_NO_EMPTY);
     $annotatedLines = array();
     foreach ($lines as $line) {
         $line = ltrim($line, "\t *");
         if (0 !== strpos($line, '@')) {
             continue;
         }
         $annotatedLines[] = $line;
     }
     if (count($annotatedLines) < 1) {
         return array();
     }
     $annotations = array();
     foreach ($annotatedLines as $annotatedLine) {
         $annotations[] = $this->annotationParser->parse($annotatedLine);
     }
     return $annotations;
 }
 /**
  * Constructor
  *
  * @param mixed $class Either a string containing the name of the class to reflect, or an object.
  * @access public
  * @return void
  */
 public function __construct($object)
 {
     parent::__construct($object);
     $parser = new AnnotationParser($this->getDocComment());
     $this->annotations = $parser->getAnnotationArray();
 }
Beispiel #6
0
 /**
  * Tests parseTypeComment with empty string.
  */
 public function testParseTypeCommentEmpty()
 {
     $annotationParser = new AnnotationParser();
     $this->assertSame(array(), $annotationParser->parseTypeComment(''));
 }
Beispiel #7
0
 private function advance()
 {
     // Hacky. Whenever we advance we check for a doc comment, and if it's there
     // we parse it for annotations and stash them. I'd previously had this check
     // in the s() method for skipping ignored tokens but that didn't work outwith
     // a class definition because phpx is essentially dumb and just passes through
     // any tokens it's not interested in.
     if (is_array($this->curr) && $this->curr[0] == T_DOC_COMMENT) {
         $this->last_annotation = null;
         try {
             $parser = new AnnotationParser();
             $annote = $parser->parse($this->current_text());
             if (count($annote)) {
                 $this->last_annotation = $annote;
             }
         } catch (\Exception $e) {
             // TODO: some form of error reporting would be good
         }
     }
     $this->ix++;
     if ($this->ix >= count($this->tokens)) {
         $this->curr = null;
     } else {
         $this->curr = $this->tokens[$this->ix];
     }
 }
 function getAnnotations()
 {
     if ($this->annotations == null) {
         $this->annotations = AnnotationParser::parse($this);
     }
     return $this->annotations;
 }
 public function testAnnotationWithZeroInNumber()
 {
     $parser = new AnnotationParser();
     $annotation = $parser->parse('@TestAnnotation(ratio = 0.15)');
     $this->assertIdentical($annotation->ratio, 0.15);
 }