當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Tokenizer\Token類代碼示例

本文整理匯總了PHP中Symfony\CS\Tokenizer\Token的典型用法代碼示例。如果您正苦於以下問題:PHP Token類的具體用法?PHP Token怎麽用?PHP Token使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Token類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: calculateTrailingWhitespaceIndent

 public static function calculateTrailingWhitespaceIndent(Token $token)
 {
     if (!$token->isWhitespace()) {
         throw new \InvalidArgumentException('The given token must be whitespace.');
     }
     return ltrim(strrchr(str_replace(array("\r\n", "\r"), "\n", $token->getContent()), 10), "\n");
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:7,代碼來源:Utils.php

示例2: process

 /**
  * {@inheritdoc}
  */
 public function process(Tokens $tokens, Token $token, $index)
 {
     $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
     $prevToken = $prevTokenIndex === null ? null : $tokens[$prevTokenIndex];
     // Skip whole class braces content.
     // That way we can skip whole tokens in class declaration, therefore skip `T_USE` for traits.
     if ($token->isClassy() && !$prevToken->isGivenKind(T_DOUBLE_COLON)) {
         $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()));
             }
         }
         return;
     }
     if ($token->isGivenKind(T_USE) && $this->isUseForLambda($tokens, $index)) {
         $token->override(array(CT_USE_LAMBDA, $token->getContent()));
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:29,代碼來源:UseTransformer.php

示例3: equals

 /**
  * Check if token is equals to given one.
  *
  * If tokens are arrays, then only keys defined in parameter token are checked.
  *
  * @param Token|array|string $other         token or it's prototype
  * @param bool               $caseSensitive perform a case sensitive comparison
  *
  * @return bool
  */
 public function equals($other, $caseSensitive = true)
 {
     $otherPrototype = $other instanceof Token ? $other->getPrototype() : $other;
     if ($this->isArray() !== is_array($otherPrototype)) {
         return false;
     }
     if (!$this->isArray()) {
         return $this->content === $otherPrototype;
     }
     $selfPrototype = $this->getPrototype();
     foreach ($otherPrototype as $key => $val) {
         // make sure the token has such key
         if (!isset($selfPrototype[$key])) {
             return false;
         }
         if (1 === $key && !$caseSensitive) {
             // case-insensitive comparison only applies to the content (key 1)
             if (0 !== strcasecmp($val, $selfPrototype[1])) {
                 return false;
             }
         } else {
             // regular comparison
             if ($selfPrototype[$key] !== $val) {
                 return false;
             }
         }
     }
     return true;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:39,代碼來源:Token.php

示例4: fixWhitespace

 private function fixWhitespace(Token $token)
 {
     $content = $token->getContent();
     if (substr_count($content, "\n") > 1) {
         $lines = Utils::splitLines($content);
         $token->setContent("\n" . end($lines));
     }
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:8,代碼來源:NoEmptyLinesAfterPhpdocsFixer.php

示例5: 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:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:12,代碼來源:ArraySquareBraceTransformer.php

示例6: 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:vuthao,項目名稱:PHP-CS-Fixer,代碼行數:13,代碼來源:ImportTransformer.php

示例7: 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:rafwlaz,項目名稱:PHP-CS-Fixer,代碼行數:15,代碼來源:NoBlankLinesAfterClassOpeningFixer.php

示例8: 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:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:ClassConstantTransformer.php

示例9: 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->equals(array(T_NS_SEPARATOR))) {
         $token->override(array(CT_NAMESPACE_OPERATOR, $token->getContent()));
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:NamespaceOperatorTransformer.php

示例10: 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:vuthao,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:ArrayTypehintTransformer.php

示例11: isValidList

 private function isValidList(Tokens $tokens, Token $docsToken, $listIndex)
 {
     $endIndex = $tokens->getNextTokenOfKind($listIndex, array(')'));
     $docsContent = $docsToken->getContent();
     for ($index = $listIndex + 1; $index < $endIndex; ++$index) {
         $token = $tokens[$index];
         if ($token->isGivenKind(T_VARIABLE) && false !== strpos($docsContent, $token->getContent())) {
             return true;
         }
     }
     return false;
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:12,代碼來源:PhpdocToCommentFixer.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]->isGivenKind(T_WHITESPACE)) {
         $tokens[$index + 1]->setContent($whitespaces . $tokens[$index + 1]->getContent());
     } else {
         $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, $whitespaces)));
     }
 }
開發者ID:rafwlaz,項目名稱:PHP-CS-Fixer,代碼行數:22,代碼來源:WhitespacyCommentTransformer.php

示例13: isValidVariable

 /**
  * Checks variable assignments for correct docblock usage.
  *
  * @param Tokens $tokens
  * @param Token  $docsToken     docs Token
  * @param int    $variableIndex index of variable Token
  *
  * @return bool
  */
 private function isValidVariable(Tokens $tokens, Token $docsToken, $variableIndex)
 {
     $nextIndex = $tokens->getNextMeaningfulToken($variableIndex);
     if (!$tokens[$nextIndex]->equals('=')) {
         return false;
     }
     return false !== strpos($docsToken->getContent(), $tokens[$variableIndex]->getContent());
 }
開發者ID:rafwlaz,項目名稱:PHP-CS-Fixer,代碼行數:17,代碼來源:PhpdocToCommentFixer.php

示例14: fixWhitespace

 /**
  * If given token is a single line whitespace then fix it to be a single space.
  *
  * @param Token $token
  */
 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace(" \t")) {
         $token->setContent(' ');
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:11,代碼來源:UnalignDoubleArrowFixer.php

示例15: fixWhitespace

 private function fixWhitespace(Token $token)
 {
     if ($token->isWhitespace(array('whitespaces' => " \t"))) {
         $token->setContent(' ');
     }
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:6,代碼來源:UnalignDoubleArrowFixer.php


注:本文中的Symfony\CS\Tokenizer\Token類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。