本文整理汇总了PHP中Token::setNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::setNamespace方法的具体用法?PHP Token::setNamespace怎么用?PHP Token::setNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::setNamespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tokenize
/**
* Tokenize source code.
*
* @param string $filename
* @param string $source
* @return File
*/
public function tokenize($filename, $source)
{
$file = new File($filename, $source);
$line = 1;
$column = 1;
$level = 0;
$namespaceFound = false;
$namespace = null;
$namespaceLevel = null;
foreach (token_get_all($source) as $token) {
if (is_array($token)) {
$type = $token[0];
$lexeme = $token[1];
} else {
$type = $token;
$lexeme = $token;
}
$token = new Token($type, $lexeme, $line, $column);
if ($token->hasNewline()) {
$line += $token->getNewLineCount();
$column = 1 + $token->getTrailingLineLength();
} else {
$column += $token->getLength();
}
// Namespace handling.
if ($type === T_NAMESPACE) {
$namespaceFound = true;
} elseif ($namespaceFound) {
if (in_array($type, array(T_STRING, T_NS_SEPARATOR))) {
$namespace .= $lexeme;
} elseif ($type === ';') {
$namespaceFound = false;
} elseif ($type === '{') {
$namespaceFound = false;
$namespaceLevel = $level;
}
} elseif ($type === '}' && $level - 1 === $namespaceLevel) {
$namespace = null;
$namespaceLevel = null;
} elseif (!$namespaceFound && $namespace !== null) {
$token->setNamespace($namespace);
}
// Block level increment.
if (in_array($type, array('(', '{', T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES))) {
$level++;
} elseif (in_array($type, array(')', '}'))) {
$level--;
}
$token->setLevel($level);
$file[] = $token;
}
return $file;
}
示例2: testNamespaceAccessors
/**
* @covers spriebsch\PHPca\Token::__construct
* @covers spriebsch\PHPca\Token::setNamespace
* @covers spriebsch\PHPca\Token::getNamespace
*/
public function testNamespaceAccessors()
{
$t = new Token(T_OPEN_TAG, '<?php');
$t->setNamespace('Foo\\Bar');
$this->assertEquals('Foo\\Bar', $t->getNamespace());
}
示例3: tokenize
//.........这里部分代码省略.........
// been parsed.
if ($namespaceFound) {
$namespace = $newNamespace;
$newNamespace = '';
$namespaceFound = false;
}
// If we encounter the opening curly brace of a class (this happens
// when $waitForClassBegin is true), we remember the block level of
// this brace so that we can end the class when we encounter the
// matching closing tag.
if ($waitForClassBegin) {
$classCurlyLevel = $level;
$waitForClassBegin = false;
}
// If we encounter the opening curly brace of an interface (this happens
// when $waitForInterfaceBegin is true), we remember the block level of
// this brace so that we can end the interface when we encounter the
// matching closing tag.
if ($waitForInterfaceBegin) {
$interfaceCurlyLevel = $level;
$waitForInterfaceBegin = false;
}
// If we encounter the opening curly brace of a class (this happens
// when $waitForClassBegin is true), we remember the block level of
// this brace so that we can end the class when we encounter the
// matching closing tag.
if ($waitForFunctionBegin) {
$functionCurlyLevel = $level;
$waitForFunctionBegin = false;
}
}
// Since we assemble any new namespace name in $newNamespace,
// we can safely always set the $namespace.
$tokenObj->setNamespace($namespace);
if ($namespaceStarted) {
$namespaceStarted = false;
$namespace = $newNamespace;
$newNamespace = '';
}
// This also sets the class when we are outside the class,
// which is harmless because we then just set an emtpy string.
if (!$waitForClassBegin) {
if (substr($class, 0, 1) == '\\' || $namespace == '\\') {
$classname = $class;
} else {
if ($class != '') {
$classname = $namespace . '\\' . $class;
} else {
$classname = '';
}
}
$tokenObj->setClass($classname);
}
// This also sets the interface when we are outside the interface,
// which is harmless because we then just set an emtpy string.
if (!$waitForInterfaceBegin) {
if (substr($interface, 0, 1) == '\\' || $namespace == '\\') {
$interfaceName = $interface;
} else {
if ($interface != '') {
$interfaceName = $namespace . '\\' . $interface;
} else {
$interfaceName = '';
}
}
$tokenObj->setInterface($interfaceName);