PhpParser\Lexer::getTokens PHP Method

getTokens() public method

The token array is in the same format as provided by the token_get_all() function and does not discard tokens (i.e. whitespace and comments are included). The token position attributes are against this token array.
public getTokens ( ) : array
return array Array of tokens in token_get_all() format
    public function getTokens()
    {
        return $this->tokens;
    }

Usage Example

Example #1
0
 private function detectTemplate()
 {
     foreach ($this->lexer->getTokens() as $token) {
         if (!is_array($token)) {
             continue;
         }
         $templateEndTokens = [T_ENDIF => 1, T_ENDFOREACH => 1, T_ENDFOR => 1, T_ENDWHILE => 1];
         if (!isset($templateEndTokens[$token[0]])) {
             continue;
         }
         if (Strings::startsWith($token[1], 'end')) {
             throw new TemplateSkippedException();
         }
     }
 }