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


PHP Tokenizer\Token类代码示例

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


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

示例1: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if ($token->isGivenKind(T_USE) && $this->isUseForLambda($tokens, $index)) {
         $token->override(array(CT_USE_LAMBDA, $token->getContent()));
     }
     if (!$token->isClassy()) {
         return;
     }
     $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $prevTokenIndex === null ? null : $tokens[$prevTokenIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         return;
     }
     // Skip whole class braces content.
     // That way we can skip whole tokens in class declaration, therefore skip `T_USE` for traits.
     $index = $tokens->getNextTokenOfKind($index, array('{'));
     $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
     while ($index < $innerLimit) {
         $token = $tokens[++$index];
         if (!$token->isGivenKind(T_USE)) {
             continue;
         }
         if ($this->isUseForLambda($tokens, $index)) {
             $token->override(array(CT_USE_LAMBDA, $token->getContent()));
         } else {
             $token->override(array(CT_USE_TRAIT, $token->getContent()));
         }
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:32,代码来源:UseTransformer.php

示例2: transformIntoDestructuringSquareBrace

 private function transformIntoDestructuringSquareBrace(Tokens $tokens, Token $token, $index)
 {
     if (null === $this->cacheOfArraySquareBraceCloseIndex || !$tokens[$tokens->getNextMeaningfulToken($this->cacheOfArraySquareBraceCloseIndex)]->equals('=')) {
         return;
     }
     $token->override(array(CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '['));
     $tokens[$this->cacheOfArraySquareBraceCloseIndex]->override(array(CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']'));
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:8,代码来源:SquareBraceTransformer.php

示例3: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$this->isShortArray($tokens, $index)) {
         return;
     }
     $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
     $token->override(array(CT_ARRAY_SQUARE_BRACE_OPEN, '['));
     $tokens[$endIndex]->override(array(CT_ARRAY_SQUARE_BRACE_CLOSE, ']'));
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:12,代码来源:ArraySquareBraceTransformer.php

示例4: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(array(T_CONST, T_FUNCTION))) {
         return;
     }
     $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
     if ($prevToken->isGivenKind(T_USE)) {
         $token->override(array($token->isGivenKind(T_FUNCTION) ? CT_FUNCTION_IMPORT : CT_CONST_IMPORT, $token->getContent()));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:13,代码来源:ImportTransformer.php

示例5: fixWhitespace

 /**
  * Cleanup a whitespace token.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     $content = $token->getContent();
     // if there is more than one new line in the whitespace, then we need to fix it
     if (substr_count($content, "\n") > 1) {
         // the final bit of the whitespace must be the next statement's indentation
         $lines = Utils::splitLines($content);
         $token->setContent("\n" . end($lines));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:15,代码来源:NoBlankLinesAfterClassOpeningFixer.php

示例6: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_NAMESPACE)) {
         return;
     }
     $nextIndex = $tokens->getNextMeaningfulToken($index);
     $nextToken = $tokens[$nextIndex];
     if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
         $token->override(array(CT::T_NAMESPACE_OPERATOR, $token->getContent()));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:14,代码来源:NamespaceOperatorTransformer.php

示例7: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equalsAny(array(array(T_CLASS, 'class'), array(T_STRING, 'class')), false)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         $token->override(array(CT::T_CLASS_CONSTANT, $token->getContent()));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:14,代码来源:ClassConstantTransformer.php

示例8: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_ARRAY)) {
         return;
     }
     $nextIndex = $tokens->getNextMeaningfulToken($index);
     $nextToken = $tokens[$nextIndex];
     if (!$nextToken->equals('(')) {
         $token->override(array(CT_ARRAY_TYPEHINT, $token->getContent()));
     }
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:14,代码来源:ArrayTypehintTransformer.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('?')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->equalsAny(array('(', ',', array(CT::T_TYPE_COLON)))) {
         $token->override(array(CT::T_NULLABLE_TYPE, '?'));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:14,代码来源:NullableTypeTransformer.php

示例10: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isGivenKind(T_CLASS)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
         $token->override(array(CT_CLASS_CONSTANT, $token->getContent()));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:14,代码来源:ClassConstantTransformer.php

示例11: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals('|')) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $tokens[$prevIndex];
     if (!$prevToken->isGivenKind(T_STRING)) {
         return;
     }
     $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
     $prevToken = $tokens[$prevIndex];
     if (!$prevToken->equalsAny(array('(', array(CT::T_TYPE_ALTERNATION)))) {
         return;
     }
     $token->override(array(CT::T_TYPE_ALTERNATION, '|'));
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:20,代码来源:TypeAlternationTransformer.php

示例12: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->isComment()) {
         return;
     }
     $content = $token->getContent();
     $trimmedContent = rtrim($content);
     // nothing trimmed, nothing to do
     if ($content === $trimmedContent) {
         return;
     }
     $whitespaces = substr($content, strlen($trimmedContent));
     $token->setContent($trimmedContent);
     if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) {
         $tokens[$index + 1]->setContent($whitespaces . $tokens[$index + 1]->getContent());
     } else {
         $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, $whitespaces)));
     }
 }
开发者ID:infinitely-young,项目名称:PHP-CS-Fixer,代码行数:22,代码来源:WhitespacyCommentTransformer.php

示例13: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     if (!$token->equals(':')) {
         return;
     }
     $endIndex = $tokens->getPrevMeaningfulToken($index);
     if (!$tokens[$endIndex]->equals(')')) {
         return;
     }
     $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex, false);
     $prevIndex = $tokens->getPrevMeaningfulToken($startIndex);
     $prevToken = $tokens[$prevIndex];
     // if this could be a function name we need to take one more step
     if ($prevToken->isGivenKind(T_STRING)) {
         $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
         $prevToken = $tokens[$prevIndex];
     }
     if ($prevToken->isGivenKind(array(T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA))) {
         $token->override(array(CT::T_TYPE_COLON, ':'));
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:24,代码来源:TypeColonTransformer.php

示例14: fixByToken

 private function fixByToken(Token $token, $index)
 {
     foreach ($this->tokenKindCallbackMap as $kind => $callback) {
         if (!$token->isGivenKind($kind)) {
             continue;
         }
         $this->{$callback}($index);
         return;
     }
     foreach ($this->tokenEqualsMap as $equals => $callback) {
         if (!$token->equals($equals)) {
             continue;
         }
         $this->{$callback}($index);
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:16,代码来源:NoExtraConsecutiveBlankLinesFixer.php

示例15: registerFoundToken

 /**
  * Register token as found.
  *
  * @param Token|array|string $token token prototype
  */
 private function registerFoundToken($token)
 {
     $tokenKind = $token instanceof Token ? $token->isArray() ? $token->getId() : $token->getContent() : (is_array($token) ? $token[0] : $token);
     $this->foundTokenKinds[$tokenKind] = true;
 }
开发者ID:GrahamForks,项目名称:PHP-CS-Fixer,代码行数:10,代码来源:Tokens.php


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