本文整理汇总了PHP中Token::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::getName方法的具体用法?PHP Token::getName怎么用?PHP Token::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: seekMatchingCurlyBrace
/**
* Seeks to the matching curly brace.
*
* @param Token $token
*/
public function seekMatchingCurlyBrace(Token $token)
{
$id = $token->getId();
$level = $token->getBlockLevel();
if ($id != T_OPEN_CURLY && $id != T_CLOSE_CURLY) {
throw new Exception($token->getName() . ' is not a curly brace');
}
// Forward search
if ($id == T_OPEN_CURLY) {
$this->next();
while ($this->valid()) {
$token = $this->current()->getId();
$closeLevel = $this->current()->getBlockLevel();
if ($token == T_CLOSE_CURLY && $closeLevel == $level) {
return;
}
$this->next();
}
}
// Backward search
if ($id == T_CLOSE_CURLY) {
$this->prev();
while ($this->valid()) {
$token = $this->current()->getId();
$openLevel = $this->current()->getBlockLevel();
if ($token == T_OPEN_CURLY && $level == $openLevel) {
return;
}
$this->prev();
}
}
// This should be impossible since in a syntactically valid
// PHP file, every opened curly brace must be closed.
throw new Exception('No matching curly brace found');
}
示例2: tokenize
public static function tokenize($string)
{
$len = strlen($string);
$tokens = array();
$current_token = new Token(Token::T_NONE, 0);
$i = 0;
while ($i < $len) {
$c = $string[$i];
switch ($c) {
case '\\':
// Escape character
$current_token->addData($string[++$i]);
break;
case ' ':
self::push($tokens, $current_token, $i);
break;
case ':':
if ($current_token->getData() == null) {
throw new ParseException('Expected T_FIELD_NAME, got nothing', $string, $i);
}
if (!$current_token->isTypeNoneOr(Token::T_FIELD_NAME)) {
throw new ParseException('Expected T_FIELD_NAME, got ' . Token::getName($current_token->getType()), $string, $i);
}
$current_token->setType(Token::T_FIELD_NAME);
self::push($tokens, $current_token, $i);
$current_token->setType(Token::T_FIELD_VALUE);
break;
case '^':
if ($current_token->getData() == null) {
throw new ParseException('Expected T_FIELD_NAME, got nothing', $string, $i);
}
if (!$current_token->isTypeNoneOr(Token::T_FIELD_NAME)) {
throw new ParseException('Expected T_FIELD_NAME, got ' . Token::getName($current_token->getType()), $string, $i);
}
$current_token->setType(Token::T_FIELD_NAME);
$field_token = $current_token;
self::push($tokens, $current_token, $i);
$current_token->setType(Token::T_FIELD_WEIGHT);
self::readInt($current_token, $string, $i);
self::push($tokens, $current_token, $i);
if ($i + 1 < $len && $string[$i + 1] == ':') {
// Peek one ahead. Duplicate T_FIELD_NAME token if a T_FIELD_VALUE follows.
$current_token = $field_token;
}
break;
case '@':
if ($current_token->getData() != null) {
throw new ParseException('Expected nothing, got ' . Token::getName($current_token->getType()), $string, $i);
}
$current_token->setType(Token::T_FIELD_SEARCH);
break;
case '"':
if ($current_token->getData() == null) {
$current_token->setTypeIfNone(Token::T_STRING);
self::readEncString($current_token, $string, $i);
if ($i + 1 < $len && $string[$i + 1] != ' ') {
// Peek one ahead. Should be empty
throw new ParseException('Unexpected T_STRING', $string, $i + 1);
}
} else {
throw new ParseException('Unexpected T_STRING', $string, $i);
}
break;
default:
$current_token->addData($c);
}
$i++;
}
self::push($tokens, $current_token, $i);
return $tokens;
}
示例3: testGetName
/**
* @covers spriebsch\PHPca\Token::__construct
* @covers spriebsch\PHPca\Token::getName
*/
public function testGetName()
{
$t = new Token(T_OPEN_TAG, '<?php');
$this->assertEquals('T_OPEN_TAG', $t->getName());
}
示例4: addColumnSqlToken
public function addColumnSqlToken(Token $token, $alias = null)
{
if (is_null($alias)) {
$i = 0;
$tokenName = $token->getName();
$tokenName = substr($tokenName, 2);
do {
$i++;
$alias = "{$tokenName}#{$i}";
} while (isset($this->columns[$alias]));
}
if (isset($this->columns[$alias])) {
throw new MalformedSqlException("Column alias '{$alias}' already defined!");
}
$this->columns[$alias] = $token;
}