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


PHP Tokens::overrideRange方法代碼示例

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


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

示例1: fix

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokensOrg)
 {
     $content = $tokensOrg->generateCode();
     // replace all <? with <?php to replace all short open tags even without short_open_tag option enabled
     $newContent = preg_replace('/<\\?(\\s|$)/', '<?php$1', $content, -1, $count);
     if (!$count) {
         return;
     }
     /* the following code is magic to revert previous replacements which should NOT be replaced, for example incorrectly replacing
      * > echo '<? ';
      * with
      * > echo '<?php ';
      */
     $tokens = Tokens::fromCode($newContent);
     $tokensOldContent = '';
     $tokensOldContentLength = 0;
     foreach ($tokens as $token) {
         if ($token->isGivenKind(T_OPEN_TAG)) {
             $tokenContent = $token->getContent();
             if ('<?php' !== substr($content, $tokensOldContentLength, 5)) {
                 $tokenContent = '<? ';
             }
             $tokensOldContent .= $tokenContent;
             $tokensOldContentLength += strlen($tokenContent);
             continue;
         }
         if ($token->isGivenKind(array(T_COMMENT, T_DOC_COMMENT, T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE, T_STRING))) {
             $tokenContent = '';
             $tokenContentLength = 0;
             $parts = explode('<?php', $token->getContent());
             $iLast = count($parts) - 1;
             foreach ($parts as $i => $part) {
                 $tokenContent .= $part;
                 $tokenContentLength += strlen($part);
                 if ($i !== $iLast) {
                     if ('<?php' === substr($content, $tokensOldContentLength + $tokenContentLength, 5)) {
                         $tokenContent .= '<?php';
                         $tokenContentLength += 5;
                     } else {
                         $tokenContent .= '<?';
                         $tokenContentLength += 2;
                     }
                 }
             }
             $token->setContent($tokenContent);
         }
         $tokensOldContent .= $token->getContent();
         $tokensOldContentLength += strlen($token->getContent());
     }
     $tokensOrg->overrideRange(0, $tokensOrg->count() - 1, $tokens);
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:54,代碼來源:ShortTagFixer.php

示例2: overrideAttribs

 /**
  * Apply token attributes.
  *
  * Token at given index is prepended by attributes.
  *
  * @param Tokens $tokens      Tokens collection
  * @param int    $memberIndex token index
  * @param array  $attribs     map of grabbed attributes, key is attribute name and value is array of index and clone of Token
  */
 private function overrideAttribs(Tokens $tokens, $memberIndex, array $attribs)
 {
     $toOverride = array();
     $firstAttribIndex = $memberIndex;
     foreach ($attribs as $attrib) {
         if (null === $attrib) {
             continue;
         }
         if (null !== $attrib['index']) {
             $firstAttribIndex = min($firstAttribIndex, $attrib['index']);
         }
         if (!$attrib['token']->isGivenKind(T_VAR) && '' !== $attrib['token']->getContent()) {
             $toOverride[] = $attrib['token'];
             $toOverride[] = new Token(array(T_WHITESPACE, ' '));
         }
     }
     if (!empty($toOverride)) {
         $tokens->overrideRange($firstAttribIndex, $memberIndex - 1, $toOverride);
     }
 }
開發者ID:skillberto,項目名稱:PHP-CS-Fixer,代碼行數:29,代碼來源:VisibilityFixer.php


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