Beispiel #1
0
 /**
  * Convert a list of tokens fromm token_get_all() into a list of
  * standardized tokens.  A description of a standardized token
  * is at the top of this class.
  *
  * @param array $tokens Token list from token_get_all()
  * @return array Standardized list of tokens
  */
 protected function standardizeTokens($tokens)
 {
     $token = null;
     $matchStack = new TokenizerMatchStack();
     $matchStackPhp = new TokenizerMatchStack();
     TokenizerToken::reset();
     $tokenObjects = array();
     $matchables = array(T_OPEN_TAG => 'matchPhpOpen', T_OPEN_TAG_WITH_ECHO => 'matchPhpOpen', T_CLOSE_TAG => 'matchPhpClose', T_CURLY_OPEN => 'matchCurlyOpen', T_DOLLAR_OPEN_CURLY_BRACES => 'matchCurlyOpen', T_TOKENIZER_BRACE_LEFT => 'matchCurlyOpen', T_TOKENIZER_BACKTICK_LEFT => 'matchBacktickOpen', T_TOKENIZER_BRACKET_LEFT => 'matchBracketOpen', T_TOKENIZER_PAREN_LEFT => 'matchParenOpen', T_TOKENIZER_BACKTICK_RIGHT => 'matchGenericClose', T_TOKENIZER_BRACE_RIGHT => 'matchGenericClose', T_TOKENIZER_BRACKET_RIGHT => 'matchGenericClose', T_TOKENIZER_PAREN_RIGHT => 'matchGenericClose', T_BAD_CHARACTER => 'matchInvalid');
     foreach ($tokens as $key => $tokenArray) {
         // Pass in the previous token for line number calculation
         $token = TokenizerToken::create($tokenArray, $token);
         $tokenObjects[] = $token;
         $tokenType = $token->getType();
         if (!empty($matchables[$tokenType])) {
             if ($this->isValid) {
                 $func = $matchables[$tokenType];
                 $this->{$func}($key, $token, $matchStack, $matchStackPhp);
             } else {
                 $token->setMatch(false);
             }
         }
     }
     if ($matchStack->length()) {
         $this->setReason('Unmatched braces left on stack.  Last one was ' . $matchStack->getToken());
     }
     // 1 open tag at the end is fine
     if ($matchStackPhp->length() > 1) {
         $this->setReason('Two open PHP tags that were not closed');
     }
     return $tokenObjects;
 }