Ejemplo n.º 1
0
 /**
  * @param int $token
  * @param string $value
  *
  * @return bool if true is returned, lexer will end its loop
  * @throws LexerException
  */
 protected function token($token, $value)
 {
     switch ($token) {
         case T_TRAIT:
             $this->source = new \stdClass();
             $this->source->name = null;
             $this->source->annotation = null;
             $this->source->constantList = [];
             $this->source->propertyList = [];
             $this->source->methodList = [];
             foreach ($this->reflectionTokenizer->getTokenStack() as $stackToken) {
                 list($innerToken, $innerValue) = $stackToken;
                 switch ($innerToken) {
                     case T_DOC_COMMENT:
                         $this->source->annotation = $innerValue;
                         break;
                 }
             }
             $this->reflectionTokenizer->getNext(T_STRING);
             $this->source->name = $this->reflectionTokenizer->current();
             break;
         case T_FUNCTION:
             if ($this->source === null) {
                 throw new LexerException(sprintf('Requested method parsing without class context - source [%d: %s].', $this->reflectionTokenizer->getLine(), $this->reflectionTokenizer->getUri()));
             }
             $methodSource = MethodLexer::build($this->reflectionTokenizer->setContinue());
             $this->source->methodList[$methodSource->name] = $methodSource;
             break;
         case T_VARIABLE:
             $this->source->propertyList = array_merge($this->source->propertyList, PropertyLexer::build($this->reflectionTokenizer->setContinue()));
             break;
         case T_CONST:
             $this->source->constantList = array_merge($this->source->constantList, ConstantLexer::build($this->reflectionTokenizer->setContinue()));
             break;
         case '{':
             $this->reflectionTokenizer->getTokenStack()->cleanup();
             $this->curly++;
             break;
         case '}':
             if (--$this->curly <= 0) {
                 return true;
             }
             break;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @param int $token
  * @param string $value
  *
  * @return bool
  * @throws LexerException
  */
 protected function token($token, $value)
 {
     switch ($token) {
         case T_CLASS:
             $this->source = new \stdClass();
             $this->source->name = null;
             $this->source->abstract = false;
             $this->source->final = false;
             $this->source->annotation = null;
             $this->source->extendList = [];
             $this->source->implementList = [];
             $this->source->constantList = [];
             $this->source->propertyList = [];
             $this->source->methodList = [];
             foreach ($this->reflectionTokenizer->getTokenStack() as $stackToken) {
                 list($innerToken, $innerValue) = $stackToken;
                 switch ($innerToken) {
                     case T_DOC_COMMENT:
                         $this->source->annotation = $innerValue;
                         break;
                     case T_ABSTRACT:
                         $this->source->abstract = true;
                         break;
                     case T_FINAL:
                         $this->source->final = true;
                         break;
                 }
             }
             $this->reflectionTokenizer->getNext(T_STRING);
             $this->source->name = $this->reflectionTokenizer->current();
             break;
         case T_EXTENDS:
             /**
              * move out of extends keyword
              */
             $this->reflectionTokenizer->next();
             $extends = null;
             foreach ($this->reflectionTokenizer->setContinue() as $innerToken => $innerValue) {
                 switch ($innerToken) {
                     case T_WHITESPACE:
                         break;
                     case T_IMPLEMENTS:
                         break 2;
                     case '{':
                         $this->reflectionTokenizer->getTokenStack()->cleanup();
                         $this->curly++;
                         break 2;
                     default:
                         $extends .= $innerValue;
                 }
             }
             /**
              * formally array for compatible interface: interface can have multiple extends
              */
             $this->source->extendList[] = $extends;
             break;
         case T_IMPLEMENTS:
             /**
              * move out of implements keyword
              */
             $this->reflectionTokenizer->next();
             $implements = null;
             foreach ($this->reflectionTokenizer->setContinue() as $innerToken => $innerValue) {
                 switch ($innerToken) {
                     case T_WHITESPACE:
                         break;
                     case ',':
                         $this->source->implementList[] = $implements;
                         $implements = null;
                         break;
                     case '{':
                         $this->reflectionTokenizer->getTokenStack()->cleanup();
                         $this->curly++;
                         $this->source->implementList[] = $implements;
                         break 2;
                     default:
                         $implements .= $innerValue;
                 }
             }
             break;
         case T_FUNCTION:
             if ($this->source === null) {
                 throw new LexerException(sprintf('Requested method parsing without class context - source [%d: %s].', $this->reflectionTokenizer->getLine(), $this->reflectionTokenizer->getUri()));
             }
             $methodSource = MethodLexer::build($this->reflectionTokenizer->setContinue());
             $this->source->methodList[$methodSource->name] = $methodSource;
             break;
         case T_VARIABLE:
             $this->source->propertyList = array_merge($this->source->propertyList, PropertyLexer::build($this->reflectionTokenizer->setContinue()));
             break;
         case T_CONST:
             $this->source->constantList = array_merge($this->source->constantList, ConstantLexer::build($this->reflectionTokenizer->setContinue()));
             break;
         case '{':
             $this->reflectionTokenizer->getTokenStack()->cleanup();
             $this->curly++;
             break;
         case '}':
             if (--$this->curly <= 0) {
                 return true;
             }
             break;
     }
     return false;
 }