* @return boolean */ public function isType($types) { if (!is_array($types)) { $types = func_get_args(); } return in_array($this->type, $types); } /** * Reset the tokenizer class between tokenization of files * * You don't need to call this directly - the Tokenizer class does this. */ public static function reset() { static::$backtickIsLeft = true; } /** * Sets the matching index. Not really a property of a token, * but so handy and useful for the tokenizer. * * @param integer $match Index in Tokenizer */ public function setMatch($match) { $this->match = $match; } } TokenizerToken::initialize();
/** * 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; }