本文整理汇总了PHP中token_get_all函数的典型用法代码示例。如果您正苦于以下问题:PHP token_get_all函数的具体用法?PHP token_get_all怎么用?PHP token_get_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了token_get_all函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: format
public function format($source)
{
$this->tkns = token_get_all($source);
$this->code = '';
$tknsLen = sizeof($this->tkns);
$touchedDoubleColon = false;
for ($ptr = 0; $ptr < $tknsLen; ++$ptr) {
$token = $this->tkns[$ptr];
list($id) = $this->getToken($token);
if (T_DOUBLE_COLON == $id) {
$touchedDoubleColon = true;
}
if ($touchedDoubleColon && T_CLASS == $id) {
$touchedDoubleColon = false;
break;
}
if (T_CLASS == $id || T_INTERFACE == $id || T_TRAIT == $id) {
$this->refWalkUsefulUntil($this->tkns, $ptr, T_STRING);
list(, $name) = $this->getToken($this->tkns[$ptr]);
$this->refWalkUsefulUntil($this->tkns, $ptr, ST_CURLY_OPEN);
$start = $ptr;
$this->refWalkCurlyBlock($this->tkns, $ptr);
$end = ++$ptr;
$this->convertToPlaceholder($name, $start, $end);
break;
}
}
return $this->render();
}
开发者ID:straiway,项目名称:fmt,代码行数:29,代码来源:ClassToSelf.php
示例2: find_methods
function find_methods($source_code, $file)
{
$class_name = "";
$tokens = token_get_all($source_code);
$in_token = false;
foreach ($tokens as $key => $token) {
switch ($token[0]) {
case T_FUNCTION:
$in_token = T_FUNCTION;
continue;
break;
case T_STRING:
switch ($in_token) {
case T_FUNCTION:
$line_num = $token[2];
$value = $token[1];
$token_type = $token[0];
$class_name .= $line_num . " " . $value . " " . $dir . '/' . $ENV['TM_FILEPATH'] . "\n";
$in_token = false;
break;
}
break;
default:
if (count($token) > 2) {
//$class_name.= "type " . token_name ($token[0]) . " line: ". $token[2] . " class " . $token[1];
}
break;
}
}
echo $class_name;
}
开发者ID:blindsight,项目名称:Magento.tmbundle,代码行数:31,代码来源:functions.php
示例3: loadFile
protected function loadFile($file)
{
$striped = "";
// remove all whitespaces and comments
// replace short tags
$t = token_get_all(str_replace('<?=', '<?php echo ', php_strip_whitespace($file)));
$blacklist = array(T_AS, T_CASE, T_INSTANCEOF, T_USE);
foreach ($t as $i => $token) {
if (is_string($token)) {
$striped .= $token;
} elseif (T_WHITESPACE === $token[0]) {
if (isset($t[$i + 1]) && is_array($t[$i + 1])) {
if (in_array($t[$i + 1][0], $blacklist)) {
$striped .= $t[$i][1];
continue;
}
if (isset($t[$i - 1]) && is_array($t[$i - 1])) {
if (in_array($t[$i - 1][0], $blacklist)) {
$striped .= $t[$i][1];
continue;
}
if ($t[$i - 1][0] == T_ECHO || $t[$i - 1][0] == T_PRINT) {
$striped .= $t[$i][1];
continue;
}
}
}
$striped .= str_replace(' ', '', $token[1]);
} else {
$striped .= $token[1];
}
}
$this->buffer = $striped;
}
开发者ID:johnarben2468,项目名称:sampleffuf-core,代码行数:34,代码来源:Compiler.php
示例4: format
public function format($source)
{
$this->tkns = token_get_all($source);
$this->code = '';
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->getToken($token);
$this->ptr = $index;
if (T_WHITESPACE == $id || T_VARIABLE == $id || T_INLINE_HTML == $id || T_COMMENT == $id || T_DOC_COMMENT == $id || T_CONSTANT_ENCAPSED_STRING == $id) {
$this->appendCode($text);
continue;
}
if (T_STRING == $id && $this->leftUsefulTokenIs([T_DOUBLE_COLON, T_OBJECT_OPERATOR])) {
$this->appendCode($text);
continue;
}
if (T_START_HEREDOC == $id) {
$this->appendCode($text);
$this->printUntil(ST_SEMI_COLON);
continue;
}
if (ST_QUOTE == $id) {
$this->appendCode($text);
$this->printUntilTheEndOfString();
continue;
}
$lcText = strtolower($text);
if (('true' === $lcText || 'false' === $lcText || 'null' === $lcText) && !$this->leftUsefulTokenIs([T_NS_SEPARATOR, T_AS, T_CLASS, T_EXTENDS, T_IMPLEMENTS, T_INSTANCEOF, T_INTERFACE, T_NEW, T_NS_SEPARATOR, T_PAAMAYIM_NEKUDOTAYIM, T_USE, T_TRAIT, T_INSTEADOF, T_CONST]) && !$this->rightUsefulTokenIs([T_NS_SEPARATOR, T_AS, T_CLASS, T_EXTENDS, T_IMPLEMENTS, T_INSTANCEOF, T_INTERFACE, T_NEW, T_NS_SEPARATOR, T_PAAMAYIM_NEKUDOTAYIM, T_USE, T_TRAIT, T_INSTEADOF, T_CONST]) || isset(static::$reservedWords[$lcText])) {
$text = $lcText;
}
$this->appendCode($text);
}
return $this->code;
}
开发者ID:Recras,项目名称:php.tools,代码行数:33,代码来源:PSR2KeywordsLowerCase.php
示例5: parse
private function parse($src, $interestedClass = null)
{
$this->tokens = token_get_all($src);
$classes = $uses = array();
$namespace = '';
while ($token = $this->next()) {
if (T_NAMESPACE === $token[0]) {
$namespace = $this->parseNamespace();
$uses = array();
} elseif (T_CLASS === $token[0] || T_INTERFACE === $token[0]) {
if ('' !== $namespace) {
$class = $namespace . '\\' . $this->nextValue();
} else {
$class = $this->nextValue();
}
$classes[$class] = $uses;
if (null !== $interestedClass && $interestedClass === $class) {
return $classes;
}
} elseif (T_USE === $token[0]) {
foreach ($this->parseUseStatement() as $useStatement) {
list($alias, $class) = $useStatement;
$uses[strtolower($alias)] = $class;
}
}
}
return $classes;
}
开发者ID:krishcdbry,项目名称:z-zangura,代码行数:28,代码来源:PhpParser.php
示例6: stripWhitespace
/**
* Strips whitespace from source. Taken from composer
* @param $source
* @return string
*/
private function stripWhitespace($source)
{
if (!function_exists('token_get_all')) {
return $source;
}
$output = '';
foreach (token_get_all($source) as $token) {
if (is_string($token)) {
$output .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
// $output .= $token[1];
$output .= str_repeat("\n", substr_count($token[1], "\n"));
} elseif (T_WHITESPACE === $token[0]) {
// reduce wide spaces
$whitespace = preg_replace('{[ \\t]+}', ' ', $token[1]);
// normalize newlines to \n
$whitespace = preg_replace('{(?:\\r\\n|\\r|\\n)}', "\n", $whitespace);
// trim leading spaces
$whitespace = preg_replace('{\\n +}', "\n", $whitespace);
$output .= $whitespace;
} else {
$output .= $token[1];
}
}
return $output;
}
开发者ID:lenninsanchez,项目名称:donadores,代码行数:31,代码来源:Compiler.php
示例7: format
public function format($source)
{
$this->tkns = token_get_all($source);
$this->code = '';
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->getToken($token);
$this->ptr = $index;
switch ($id) {
case T_WHILE:
$str = $text;
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->getToken($token);
$this->ptr = $index;
$str .= $text;
if (ST_CURLY_OPEN == $id || ST_COLON == $id || ST_SEMI_COLON == $id && (ST_SEMI_COLON == $ptId || ST_CURLY_OPEN == $ptId || T_COMMENT == $ptId || T_DOC_COMMENT == $ptId)) {
$this->appendCode($str);
break;
} elseif (ST_SEMI_COLON == $id && !(ST_SEMI_COLON == $ptId || ST_CURLY_OPEN == $ptId || T_COMMENT == $ptId || T_DOC_COMMENT == $ptId)) {
$this->rtrimAndAppendCode($str);
break;
}
}
break;
case T_WHITESPACE:
$this->appendCode($text);
break;
default:
$ptId = $id;
$this->appendCode($text);
break;
}
}
return $this->code;
}
开发者ID:straiway,项目名称:fmt,代码行数:34,代码来源:MergeCurlyCloseAndDoWhile.php
示例8: preWrite
/**
* @param cfhCompile_CodeWriter $codeWriter
* @param cfhCompile_Class_Interface $class
* @param unknown_type $sourceCode
* @param cfhCompile_ClassRegistry $classRegistry
* @return String
*/
public function preWrite(cfhCompile_CodeWriter $codeWriter, cfhCompile_Class_Interface $class, $sourceCode, cfhCompile_ClassRegistry $classRegistry)
{
if (is_null($sourceCode)) {
return NULL;
}
$tokens = token_get_all('<?php ' . $sourceCode);
$sourceCode = '';
$lastWasString = FALSE;
while ($token = current($tokens)) {
$nextIsString = is_string(next($tokens));
prev($tokens);
if (is_string($token)) {
$sourceCode .= $token;
$lastWasString = TRUE;
} else {
list($token, $text) = $token;
if ($token == T_WHITESPACE) {
if ($lastWasString === FALSE && $nextIsString === FALSE) {
$sourceCode .= ' ';
}
} else {
$sourceCode .= $text;
}
$lastWasString = FALSE;
}
next($tokens);
}
return trim(substr($sourceCode, 5));
}
开发者ID:googlecode-mirror,项目名称:cfh-compile,代码行数:36,代码来源:StripWhiteSpace.php
示例9: register
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
// Everyone has had a chance to figure out what forbidden functions
// they want to check for, so now we can cache out the list.
$this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
if ($this->patternMatch === true) {
foreach ($this->forbiddenFunctionNames as $i => $name) {
$this->forbiddenFunctionNames[$i] = '/' . $name . '/i';
}
return array(T_STRING);
}
// If we are not pattern matching, we need to work out what
// tokens to listen for.
$string = '<?php ';
foreach ($this->forbiddenFunctionNames as $name) {
$string .= $name . '();';
}
$register = array();
$tokens = token_get_all($string);
array_shift($tokens);
foreach ($tokens as $token) {
if (is_array($token) === true) {
$register[] = $token[0];
}
}
return array_unique($register);
}
开发者ID:kmiku7,项目名称:PHP_CodeSniffer-2.3.2-annotated,代码行数:32,代码来源:ForbiddenFunctionsSniff.php
示例10: handleTraitFile
public function handleTraitFile($basename, $pathname, $depth)
{
$traits = null;
// The results of individual file parses are cached, since only a few
// files will have changed and TokenisedRegularExpression is quite
// slow. A combination of the file name and file contents hash are used,
// since just using the datetime lead to problems with upgrading.
$file = file_get_contents($pathname);
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $basename) . '_' . md5($file);
if ($data = $this->cache->load($key)) {
$valid = isset($data['traits']) && isset($data['namespace']) && is_array($data['traits']) && is_string($data['namespace']);
if ($valid) {
$traits = $data['traits'];
$namespace = $data['namespace'];
}
}
if (!$traits) {
$tokens = token_get_all($file);
$namespace = self::get_namespace_parser()->findAll($tokens);
if ($namespace) {
$namespace = implode('', $namespace[0]['namespaceName']) . '\\';
} else {
$namespace = '';
}
$traits = self::get_trait_parser()->findAll($tokens);
$cache = array('traits' => $traits, 'namespace' => $namespace);
$this->cache->save($cache, $key);
}
foreach ($traits as $trait) {
$this->traits[strtolower($namespace . $trait['traitName'])] = $pathname;
}
}
开发者ID:markguinn,项目名称:trait-loader,代码行数:32,代码来源:TraitManifest.php
示例11: format
public function format($source)
{
$this->tkns = token_get_all($source);
$this->code = '';
$touchedDoubleArrow = false;
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->getToken($token);
$this->ptr = $index;
if (T_DOUBLE_ARROW == $id) {
$touchedDoubleArrow = true;
$this->appendCode($text);
continue;
}
if ($touchedDoubleArrow) {
if (T_WHITESPACE == $id || T_DOC_COMMENT == $id || T_COMMENT == $id) {
$this->appendCode($text);
continue;
}
if (T_ARRAY === $id) {
$this->rtrimAndAppendCode($text);
$touchedDoubleArrow = false;
continue;
}
$touchedDoubleArrow = false;
}
$this->appendCode($text);
}
return $this->code;
}
开发者ID:Recras,项目名称:php.tools,代码行数:29,代码来源:MergeDoubleArrowAndArray.php
示例12: compress_code
function compress_code($content)
{
$strip_str = "";
$tokens = token_get_all($content);
$last_space = FALSE;
$i = 0;
$j = count($tokens);
for (; $i < $j; ++$i) {
if (is_string($tokens[$i])) {
$last_space = FALSE;
$strip_str .= $tokens[$i];
} else {
switch ($tokens[$i][0]) {
case T_COMMENT:
case T_DOC_COMMENT:
case T_WHITESPACE:
if ($last_space) {
break;
}
$strip_str .= " ";
$last_space = TRUE;
break;
default:
$last_space = FALSE;
$strip_str .= $tokens[$i][1];
}
}
}
return $strip_str;
}
开发者ID:my1977,项目名称:shopnc,代码行数:30,代码来源:build.php
示例13: getClassInfo
/**
* Returns an array that contains namespace and name of the class defined in the file
*
* Code losely based on http://stackoverflow.com/questions/7153000/get-class-name-from-file
* by user http://stackoverflow.com/users/492901/netcoder
*
* @param string file to anaylse
* @return array
*/
public static function getClassInfo($file)
{
$buffer = file_get_contents($file);
$tokens = @token_get_all($buffer);
$class = $namespace = $buffer = '';
for ($i = 0; $i < count($tokens); $i++) {
if ($tokens[$i][0] === T_NAMESPACE) {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j][0] === T_STRING) {
$namespace .= '\\' . $tokens[$j][1];
} else {
if ($tokens[$j] === '{' || $tokens[$j] === ';') {
break;
}
}
}
}
if ($tokens[$i][0] === T_CLASS) {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j] === '{') {
if (!isset($tokens[$i + 2][1])) {
error_log($file . ' does not contain a valid class definition');
break;
} else {
$class = $tokens[$i + 2][1];
}
}
}
}
}
return array('ns' => $namespace, 'class' => $class);
}
开发者ID:nagyist,项目名称:generis,代码行数:41,代码来源:class.PhpTools.php
示例14: get_class_name
/**
* Gets the class and adds into the map
*/
private static function get_class_name($FileName)
{
$Tokens = token_get_all(file_get_contents($FileName));
$IsTestable = false;
$IsClass = false;
foreach ($Tokens as $Token) {
if (is_array($Token)) {
if (!$IsTestable && $Token[0] == T_DOC_COMMENT && strpos($Token[1], "@TestClass")) {
$IsTestable = true;
}
if ($IsTestable && $Token[0] == T_CLASS) {
$IsClass = true;
} else {
if ($IsClass && $Token[0] == T_STRING) {
$ReflectionClass = new ReflectionClass($Token[1]);
if (count(self::get_testable_methods($ReflectionClass))) {
self::$Classes[$Token[1]] = new ReflectionClass($Token[1]);
}
$IsTestable = false;
$IsClass = false;
}
}
}
}
}
开发者ID:Kufirc,项目名称:Gazelle,代码行数:28,代码来源:testing.class.php
示例15: findClass
/**
* Returns the full class name for the first class in the file.
*
* @param string $file A PHP file path
*
* @return string|false Full class name if found, false otherwise
*/
protected function findClass($file)
{
$class = false;
$namespace = false;
$tokens = token_get_all(file_get_contents($file));
for ($i = 0, $count = count($tokens); $i < $count; $i++) {
$token = $tokens[$i];
if (!is_array($token)) {
continue;
}
if (true === $class && T_STRING === $token[0]) {
return $namespace . '\\' . $token[1];
}
if (true === $namespace && T_STRING === $token[0]) {
$namespace = '';
do {
$namespace .= $token[1];
$token = $tokens[++$i];
} while ($i < $count && is_array($token) && in_array($token[0], array(T_NS_SEPARATOR, T_STRING)));
}
if (T_CLASS === $token[0]) {
$class = true;
}
if (T_NAMESPACE === $token[0]) {
$namespace = true;
}
}
return false;
}
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:36,代码来源:AnnotationFileLoader.php
示例16: format
public function format($source)
{
$this->tkns = token_get_all($source);
$this->code = '';
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->getToken($token);
$this->ptr = $index;
switch ($id) {
case T_NAMESPACE:
if ($this->rightUsefulTokenIs(T_NS_SEPARATOR)) {
break;
}
$this->appendCode($text);
list($foundId, $foundText) = $this->printAndStopAt([ST_CURLY_OPEN, ST_SEMI_COLON]);
if (ST_CURLY_OPEN == $foundId) {
$this->appendCode($foundText);
$this->printCurlyBlock();
} elseif (ST_SEMI_COLON == $foundId) {
$this->appendCode(ST_CURLY_OPEN);
list($foundId, $foundText) = $this->printAndStopAt([T_NAMESPACE, T_CLOSE_TAG]);
if (T_CLOSE_TAG == $foundId) {
return $source;
}
$this->appendCode($this->getCrlf() . ST_CURLY_CLOSE . $this->getCrlf());
prev($this->tkns);
continue;
}
break;
default:
$this->appendCode($text);
}
}
return $this->code;
}
开发者ID:studiokiwik,项目名称:php.tools,代码行数:34,代码来源:EncapsulateNamespaces.php
示例17: token_get_all_nl
function token_get_all_nl($source)
{
$new_tokens = array();
// Get the tokens
$tokens = token_get_all($source);
// Split newlines into their own tokens
foreach ($tokens as $token) {
$token_name = is_array($token) ? $token[0] : null;
$token_data = is_array($token) ? $token[1] : $token;
// Do not split encapsed strings or multiline comments
if ($token_name == T_CONSTANT_ENCAPSED_STRING || substr($token_data, 0, 2) == '/*') {
$new_tokens[] = array($token_name, $token_data);
continue;
}
// Split the data up by newlines
$split_data = preg_split('#(\\r\\n|\\n)#', $token_data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ($split_data as $data) {
if ($data == "\r\n" || $data == "\n") {
// This is a new line token
$new_tokens[] = array(T_NEW_LINE, $data);
} else {
// Add the token under the original token name
$new_tokens[] = is_array($token) ? array($token_name, $data) : $data;
}
}
}
return $new_tokens;
}
开发者ID:hensonvip,项目名称:ymroad,代码行数:28,代码来源:util.helper.php
示例18: compress_code
/**
* 压缩PHP代码
*
* @param string $content 压缩内容
* @return string
*/
function compress_code($content)
{
$strip_str = '';
//分析php源码
$tokens = token_get_all($content);
$last_space = false;
for ($i = 0, $j = count($tokens); $i < $j; $i++) {
if (is_string($tokens[$i])) {
$last_space = false;
$strip_str .= $tokens[$i];
} else {
switch ($tokens[$i][0]) {
//过滤各种PHP注释
case T_COMMENT:
case T_DOC_COMMENT:
break;
//过滤空格
//过滤空格
case T_WHITESPACE:
if (!$last_space) {
$strip_str .= ' ';
$last_space = true;
}
break;
default:
$last_space = false;
$strip_str .= $tokens[$i][1];
}
}
}
return $strip_str;
}
开发者ID:dotku,项目名称:shopnc_cnnewyork,代码行数:38,代码来源:build.php
示例19: processSource
/**
* Extracts tokens from a source code.
*
* @param string $source Source code
*/
protected final function processSource($source)
{
$stream = @token_get_all(str_replace(array("\r\n", "\r"), "\n", $source));
static $checkLines = array(T_COMMENT => true, T_WHITESPACE => true, T_DOC_COMMENT => true, T_INLINE_HTML => true, T_ENCAPSED_AND_WHITESPACE => true, T_CONSTANT_ENCAPSED_STRING => true);
foreach ($stream as $position => $token) {
if (is_array($token)) {
if (!NATIVE_TRAITS && T_STRING === $token[0]) {
$lValue = strtolower($token[1]);
if ('trait' === $lValue) {
$token[0] = T_TRAIT;
} elseif ('insteadof' === $lValue) {
$token[0] = T_INSTEADOF;
} elseif ('__TRAIT__' === $token[1]) {
$token[0] = T_TRAIT_C;
} elseif ('callable' === $lValue) {
$token[0] = T_CALLABLE;
}
}
$this->tokens[] = $token;
} else {
$previous = $this->tokens[$position - 1];
$line = $previous[2];
if (isset($checkLines[$previous[0]])) {
$line += substr_count($previous[1], "\n");
}
$this->tokens[] = array($token, $token, $line);
}
}
$this->count = count($this->tokens);
}
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:35,代码来源:StreamBase.php
示例20: get_php_classes
function get_php_classes($php_code, $onlypublic)
{
$classes = array();
$methods = array();
$tokens = token_get_all($php_code);
$count = count($tokens);
for ($i = 2; $i < $count; $i++) {
if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
$class_name = $tokens[$i][1];
$methods[$class_name] = array();
}
if ($tokens[$i - 2][0] == T_FUNCTION && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
if ($onlypublic) {
if (!in_array($tokens[$i - 4][0], array(T_PROTECTED, T_PRIVATE))) {
$method_name = $tokens[$i][1];
$methods[$class_name][] = $method_name;
}
} else {
$method_name = $tokens[$i][1];
$methods[$class_name][] = $method_name;
}
}
}
return $methods;
}
开发者ID:b-rucel,项目名称:code-snippets,代码行数:25,代码来源:readsource.php
注:本文中的token_get_all函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论