public function testIs() { $token = new Token(Token::T_ECHO, "echo", 1); $this->assertTrue($token->is(Token::T_ECHO)); $this->assertTrue($token->is(array(Token::T_ECHO, Token::T_CLASS))); $this->assertFalse($token->is(Token::T_CLASS)); $this->assertFalse($token->is(array(Token::T_USE, Token::T_CLASS))); }
/** * Builds a new instance of this enum using a token to determine the value * * @param \vc\Tokens\Token $token * @return \vc\Data\Visibility */ public static function fromToken(\vc\Tokens\Token $token) { if ($token->is(Token::T_PUBLIC)) { return self::vPublic(); } else { if ($token->is(Token::T_PROTECTED)) { return self::vProtected(); } else { if ($token->is(Token::T_PRIVATE)) { return self::vPrivate(); } } } throw new \r8\Exception\Argument(0, "Token", "Invalid token source"); }
/** * Builds a token from a mixed input * * @param Mixed $input * @return \vc\Tokens\Token */ private function buildToken($input) { // In most cases, token_get_all represents a token as an array if (is_array($input)) { return \vc\Tokens\Token::fromArray($input); } // When a token is reinstated, its object gets shifted onto this list if ($input instanceof \vc\Tokens\Token) { return $input; } // For custom tokens, we need to derive the line number based on the // previous token. If the previous token contains a carriage return, // then we need to manually bump the value up $line = $this->current->getLine(); if ($this->current->is(\vc\Tokens\Token::T_WHITESPACE)) { $content = $this->current->getContent(); $line += substr_count($content, "\n") + substr_count($content, "\r"); } return new \vc\Tokens\Token(self::lookupToken($input), $input, $line); }