当前位置: 首页>>代码示例>>PHP>>正文


PHP token_name函数代码示例

本文整理汇总了PHP中token_name函数的典型用法代码示例。如果您正苦于以下问题:PHP token_name函数的具体用法?PHP token_name怎么用?PHP token_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了token_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _runPHP

 private function _runPHP()
 {
     $this->_source = "return " . $this->_source . ";";
     if (function_exists("token_get_all")) {
         //tokenizer extension may be disabled
         $php = "<?php\n" . $this->_source . "\n?>";
         $tokens = token_get_all($php);
         foreach ($tokens as $token) {
             $type = $token[0];
             if (is_long($type)) {
                 if (in_array($type, array(T_OPEN_TAG, T_RETURN, T_WHITESPACE, T_ARRAY, T_LNUMBER, T_DNUMBER, T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_ARROW, T_CLOSE_TAG, T_NEW))) {
                     continue;
                 }
                 if ($type == T_STRING) {
                     $func = strtolower($token[1]);
                     if (in_array($func, array("mongoid", "mongocode", "mongodate", "mongoregex", "mongobindata", "mongoint32", "mongoint64", "mongodbref", "mongominkey", "mongomaxkey", "mongotimestamp", "true", "false", "null"))) {
                         continue;
                     }
                 }
                 exit("For your security, we stoped data parsing at '(" . token_name($type) . ") " . $token[1] . "'.");
             }
         }
     }
     return eval($this->_source);
 }
开发者ID:jango2015,项目名称:nette-mongodb-sandbox,代码行数:25,代码来源:VarEval.php

示例2: tokenize

 /**
  * Splits the provided `$code` into PHP language tokens.
  *
  * @param string $code Source code to be tokenized.
  * @param array $options Options consists of:
  *        -'wrap': Boolean indicating whether or not to wrap the supplied
  *          code in PHP tags.
  *        -'ignore': An array containing PHP language tokens to ignore.
  *        -'include': If supplied, an array of the only language tokens
  *         to include in the output.
  * @return array An array of tokens in the supplied source code.
  */
 public static function tokenize($code, array $options = array())
 {
     $defaults = array('wrap' => true, 'ignore' => array(), 'include' => array());
     $options += $defaults;
     $tokens = array();
     $line = 1;
     if ($options['wrap']) {
         $code = "<?php {$code}?>";
     }
     foreach (token_get_all($code) as $token) {
         $token = isset($token[1]) ? $token : array(null, $token, $line);
         list($id, $content, $line) = $token;
         $name = $id ? token_name($id) : $content;
         if (!empty($options['include'])) {
             if (!in_array($name, $options['include']) && !in_array($id, $options['include'])) {
                 continue;
             }
         }
         if (!empty($options['ignore'])) {
             if (in_array($name, $options['ignore']) || in_array($id, $options['ignore'])) {
                 continue;
             }
         }
         $tokens[] = array('id' => $id, 'name' => $name, 'content' => $content, 'line' => $line);
         if ($id === T_WHITESPACE) {
             $line += count(preg_split('/\\r\\n|\\r|\\n/', $content)) - 1;
         }
     }
     if ($options['wrap'] && empty($options['include'])) {
         $tokens = array_slice($tokens, 1, count($tokens) - 2);
     }
     return $tokens;
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:45,代码来源:Parser.php

示例3: token_name_nl

 function token_name_nl($token)
 {
     if ($token === T_NEW_LINE) {
         return 'T_NEW_LINE';
     }
     return token_name($token);
 }
开发者ID:hensonvip,项目名称:ymroad,代码行数:7,代码来源:util.helper.php

示例4: _outputFriendlyErrors

 /**
  * Output user friendly error messages
  *
  * The message is based on the token ID
  *
  * @param array $errors List of errors for the file
  * @param string $file Path to the file that was tokenized
  * @return void
  */
 protected function _outputFriendlyErrors($errors, $file)
 {
     $file = $this->_normalizeFilePath($file);
     $this->log(sprintf('%s (%d errors)', $file, sizeof($errors)), 'info');
     foreach ($errors as $error) {
         switch ($error[0]) {
             case T_EXIT:
                 $this->_outputError('die() statements not allowed in views', $error);
                 break;
             case T_ECHO:
                 $this->_outputError('echo() statements not allowed in views', $error);
                 break;
             case T_VARIABLE:
                 $this->_outputError('Unsafe variable output for "' . $error[1] . '". Please wrap in h()', $error);
                 break;
             case T_REQUIRE:
                 $this->_outputError('Using require() inside a View is not allowed, use $this->element()', $error);
                 break;
             case T_INCLUDE:
                 $this->_outputError('Using include() inside a View is not allowed, use $this->element()', $error);
                 break;
             default:
                 debug(token_name($error[0]));
                 debug($error);
                 break;
         }
     }
 }
开发者ID:nodesagency,项目名称:cakephp-security,代码行数:37,代码来源:ViewTask.php

示例5: analizeToken

 /**
  * Разбор блока
  *
  * @param array $token
  * @param integer $i
  * @param integer $init
  * @return string
  */
 public static function analizeToken($token, $i, $init)
 {
     $result = "";
     switch (token_name((int) $token[0])) {
         case "T_WHITESPACE":
         case "T_ENCAPSED_AND_WHITESPACE":
             // New line between commands fixer
             $result .= " ";
             break;
             // [ FIXME ]: Implement a fix for this situation
         // [ FIXME ]: Implement a fix for this situation
         case "T_CONSTANT_ENCAPSED_STRING":
             // New line in string definition fixer
             $result .= $token[1];
             break;
         case "T_OPEN_TAG":
             if ($i == $init && is_array($token[1])) {
                 // Last weird behavior of PHP Tokenizer... it puts
                 // the first PHP command as part of the T_OPEN_TAG
                 $result .= Miaox_Aop_CodeCruncher::analizeToken($token[1], $i, $init);
             } else {
                 $result .= trim($token[1]);
             }
             break;
         case "T_COMMENT":
         case "T_ML_COMMENT":
         case "T_DOC_COMMENT":
             // Do nothing
             break;
         default:
             $result .= $token[1];
             break;
     }
     return $result;
 }
开发者ID:theratg,项目名称:miaox,代码行数:43,代码来源:CodeCruncher.class.php

示例6: getAllUseStatements

 public function getAllUseStatements($contents)
 {
     $tokens = token_get_all($contents);
     $shortName = $className = '';
     $useNamespace = $useFlag = $asFlag = 0;
     $result = array();
     foreach ($tokens as $token) {
         if (is_array($token)) {
             if (token_name($token[0]) == 'T_WHITESPACE') {
                 // $useNamespace = 0;
                 continue;
             }
             if (token_name($token[0]) == 'T_NAMESPACE') {
                 $useNamespace = 1;
                 continue;
             }
             if (token_name($token[0]) == 'T_CLASS') {
                 break;
             }
             if (token_name($token[0]) == 'T_USE') {
                 $useFlag = 1;
                 $useNamespace = 0;
                 continue;
             }
             if (strtolower($token[1]) == 'as') {
                 $asFlag = 1;
                 continue;
             }
             if ($useNamespace) {
                 $this->currentNamespace .= $token[1];
             }
             if ($useFlag && !$asFlag) {
                 $className .= $token[1];
             }
             if ($asFlag) {
                 $shortName = $token[1];
                 $asFlag = 0;
             }
             // start keeping class
         } else {
             if ($useFlag && ($token == ';' || $token == ',')) {
                 $className = trim($className);
                 if (!$shortName) {
                     try {
                         $shortName = $this->getShortName($className);
                     } catch (\Exception $e) {
                         // Errored
                         continue;
                     }
                 }
                 $result[$shortName] = $className;
                 if ($token == ',') {
                     $useFlag = 1;
                 }
                 $shortName = $className = '';
             }
         }
     }
     return $result;
 }
开发者ID:shameerc,项目名称:php-hyperclick,代码行数:60,代码来源:FQCN.php

示例7: mutate

 public function mutate(MutationInterface $original, $index)
 {
     $token = $original->getTokens()->offsetGet($index);
     if ($token->getType() !== T_ELSE) {
         throw new \UnexpectedValueException(sprintf('invalid token "%s" given in %s', token_name($token->getType()), get_class($this)));
     }
     // look for the closing bracket
     $tokens = $original->getTokens();
     $len = $tokens->count();
     $end = false;
     for ($i = $index; $i < $len; $i++) {
         $token = $tokens->offsetGet($i);
         if ($token->getType() === T_STRING && $token->getValue() === '}') {
             $end = $i;
             break;
         }
     }
     if (false === $end) {
         throw new \OutOfRangeException('closing bracket not found for else');
     }
     // remove all concerned tokens
     $tokens = $tokens->remove($index, $end);
     $new = new \Hal\MutaTesting\Mutation\Mutation();
     $new->setTokens($tokens)->setUnit($original->getUnit())->setSourceFile($original->getSourceFile())->setTestFile($original->getTestFile())->setMutedTokensIndexes(array_merge($original->getMutedTokensIndexes(), range($index, $end)));
     return $new;
 }
开发者ID:halleck45,项目名称:mutatesting,代码行数:26,代码来源:MutaterElse.php

示例8: tokenize

 public static function tokenize($code, $options = array())
 {
     $defaults = array('wrap' => true, 'ignore' => array(), 'include' => array());
     $options += $defaults;
     $tokens = array();
     $line = 1;
     if ($options['wrap']) {
         $code = "<?php {$code}?>";
     }
     foreach (token_get_all($code) as $token) {
         $token = is_array($token) ? $token : array(null, $token, $line);
         list($id, $content, $line) = $token;
         $name = $id ? token_name($id) : $content;
         if (!empty($options['include'])) {
             if (!in_array($name, $options['include']) && !in_array($id, $options['include'])) {
                 continue;
             }
         }
         if (in_array($name, $options['ignore']) || in_array($id, $options['ignore'])) {
             continue;
         }
         $tokens[] = compact('id', 'name', 'content', 'line');
     }
     if ($options['wrap'] && empty($options['include'])) {
         $tokens = array_slice($tokens, 1, count($tokens) - 2);
     }
     return $tokens;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:28,代码来源:Parser.php

示例9: getName

 /**
  * @return string
  */
 public function getName()
 {
     if ('UNKNOWN' === $this->name) {
         $this->setName(token_name($this->getId()));
     }
     return $this->name;
 }
开发者ID:nafigator,项目名称:Veles,代码行数:10,代码来源:PhpToken.php

示例10: getFunction

 private function getFunction($idTocken)
 {
     $function = $this->tokens[$idTocken][1];
     $level = 0;
     $nom = null;
     $canBeStore = false;
     for ($idTocken = $idTocken + 1; $idTocken < count($this->tokens); $idTocken++) {
         $token = $this->tokens[$idTocken];
         if (is_null($nom) && token_name($token[0]) == 'T_STRING') {
             $nom = $token[1];
         }
         if ($token === '{') {
             $level++;
         } elseif (is_array($token) && $token[0] == 383) {
             $level++;
         } elseif ($token === '}') {
             $level--;
             $canBeStore = true;
         }
         if (is_array($token)) {
             $function .= $token[1];
         } else {
             $function .= $token;
         }
         if ($canBeStore && $level == 0) {
             self::$history[$this->fileName][$nom] = $function;
             return $idTocken;
         }
     }
 }
开发者ID:fzed51,项目名称:import,代码行数:30,代码来源:SourceFile.php

示例11: getClassnameForToken

 public function getClassnameForToken(Token $token)
 {
     $type = $token->getType();
     $value = $token->getValue();
     $classname = null;
     switch ($type) {
         case T_STRING:
             // case of operators
             if (isset(self::$OPERATOR_MAP[$value])) {
                 $classname = self::$OPERATOR_MAP[$value];
             }
             break;
         default:
             $classname = token_name($type);
             break;
     }
     // camelcase
     $classname = strtolower($classname);
     $classname = preg_replace_callback('/_(.?)/', function ($matches) {
         return strtoupper($matches[1]);
     }, $classname);
     $classname = preg_replace('!(^t)!', '', $classname);
     if (null !== $classname) {
         $classname = '\\Hal\\MutaTesting\\Mutater\\Mutater' . $classname;
     }
     return $classname;
 }
开发者ID:halleck45,项目名称:mutatesting,代码行数:27,代码来源:MutaterFactory.php

示例12: __construct

 public function __construct($tokens)
 {
     // The stack, each entry should look like:
     //  [ $func, $index
     $stack = [];
     $history = [];
     // Need a first sweep to detect all possible entry points into the code
     $entrypoints = [];
     foreach ($tokens as $tok) {
         // Find all "function" tokens and the first code lines after opening tags
     }
     // Scann all the tokens here, try to follow execution flow building a stack and matching it against criteria
     foreach ($tokens as $tok) {
         switch ($tok[0]) {
             case T_WHITESPACE:
                 break;
             default:
                 if (is_string($tok[0])) {
                     printf("Skipping stringtoken '%s'\n", $tok[0]);
                 } else {
                     printf("Skipping token %s (%s)\n", token_name($tok[0]), "'" . join("','", array_slice($tok, 1)) . "'");
                 }
                 break;
         }
     }
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:26,代码来源:phpthreat.php

示例13: execute

 protected function execute(InputInterface $in, OutputInterface $out)
 {
     $file = $in->getArgument('target');
     if (!is_file($file) || !is_readable($file)) {
         $out->writeln(sprintf('<error>"%s" is not a valid file!</error>', $file));
         return;
     }
     $tokenizer = $in->getOption('tokenizer');
     if ($tokenizer === 'php') {
         $tokens = token_get_all(file_get_contents($file));
         foreach ($tokens as $token) {
             if (is_array($token)) {
                 $out->writeln(sprintf('%s(%s) "%s"', token_name($token[0]), $token[0], $token[1]));
             } else {
                 $out->writeln('"' . $token . '"');
             }
         }
     } elseif ($tokenizer === 'lib') {
         $lexer = ExtendedEmulativeLexer::createDefaultInstance();
         $lexer->startLexing(file_get_contents($file));
         $offset = 0;
         while ($id = $lexer->getNextToken()) {
             if (is_string($name = $this->libTokenToTokenName($id))) {
                 $out->writeln($name . '(' . $lexer->getTokens()[$offset][0] . ') ' . $lexer->getTokens()[$offset][1]);
             } else {
                 $out->writeln('Discarded token with id ' . $id);
             }
             $offset++;
         }
     } else {
         $out->writeln(sprintf('<error>"%s" is not a valid value for the tokenizer option</error>', $tokenizer));
     }
 }
开发者ID:suralc,项目名称:pvra,代码行数:33,代码来源:DumpTokenListCommand.php

示例14: getType

 function getType()
 {
     if (is_string($this->data)) {
         switch ($this->data) {
             case T_BLOCK_OPEN:
                 return "T_BLOCK_OPEN";
             case T_BLOCK_CLOSE:
                 return "T_BLOCK_CLOSE";
             case T_ARRAY_INDEX_OPEN:
                 return "T_ARRAY_INDEX_OPEN";
             case T_ARRAY_INDEX_CLOSE:
                 return "T_ARRAY_INDEX_CLOSE";
             case T_ROUND_BRACE_OPEN:
                 return "T_ROUND_BRACE_OPEN";
             case T_ROUND_BRACE_CLOSE:
                 return "T_ROUND_BRACE_CLOSE";
             case T_EQUAL:
                 return "T_EQUAL";
             case T_COLON:
                 return "T_COLON";
             case T_SEMICOLON:
                 return "T_SEMICOLON";
             default:
                 return "T_STRING";
         }
     } else {
         list($id, $text) = $this->data;
         return token_name($id);
     }
 }
开发者ID:mbcraft,项目名称:frozen,代码行数:30,代码来源:PHPToken.class.php

示例15: getTokenType

 function getTokenType($num)
 {
     if ($num > count($this->tokens) || $num < 0) {
         throw new InvalidParameterException("Invalid token number!!");
     }
     $tk = $this->tokens[$num];
     if (is_string($tk)) {
         switch ($tk) {
             case '{':
                 return "T_BLOCK_OPEN";
             case '}':
                 return "T_BLOCK_CLOSE";
             case '[':
                 return "T_ARRAY_INDEX_OPEN";
             case ']':
                 return "T_ARRAY_INDEX_CLOSE";
             case '(':
                 return "T_ROUND_BRACE_OPEN";
             case ')':
                 return "T_ROUND_BRACE_CLOSE";
             case '=':
                 return "T_EQUAL";
             case ',':
                 return "T_COLON";
             case ';':
                 return "T_SEMICOLON";
             default:
                 return "T_STRING";
         }
     } else {
         list($id, $text) = $tk;
         return token_name($id);
     }
 }
开发者ID:mbcraft,项目名称:frozen,代码行数:34,代码来源:PHPParser.class.php


注:本文中的token_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。