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


PHP PHP_CodeSniffer::standardDir方法代碼示例

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


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

示例1: setTokenListeners

 /**
  * Sets installed sniffs in the coding standard being used.
  *
  * Traverses the standard directory for classes that implement the
  * PHP_CodeSniffer_Sniff interface asks them to register. Each of the
  * sniff's class names must be exact as the basename of the sniff file.
  * If the standard is a file, will skip transversal and just load sniffs
  * from the file.
  *
  * @param string $standard The name of the coding standard we are checking.
  *                         Can also be a path to a custom standard dir
  *                         containing a ruleset.xml file or can be a path
  *                         to a custom ruleset file.
  * @param array  $sniffs   The sniff names to restrict the allowed
  *                         listeners to.
  *
  * @return void
  * @throws PHP_CodeSniffer_Exception If the standard is not valid.
  */
 public function setTokenListeners($standard, array $sniffs = array())
 {
     if (is_dir($standard) === true) {
         // This is an absolute path to a custom standard.
         self::$standardDir = $standard;
         $standard = basename($standard);
     } else {
         if (is_file($standard) === true) {
             // Might be a custom ruleset file.
             $ruleset = simplexml_load_file($standard);
             if ($ruleset === false) {
                 throw new PHP_CodeSniffer_Exception("Ruleset {$standard} is not valid");
             }
             if (basename($standard) === 'ruleset.xml') {
                 // The ruleset uses the generic name, so this may actually
                 // be a complete standard with it's own sniffs. By setting the
                 // the standardDir to be the directory, we will process both
                 // the directory (for custom sniffs) and the ruleset.xml file
                 // (as it uses the generic name) in getSniffFiles.
                 self::$standardDir = dirname($standard);
             } else {
                 // This is a custom ruleset file with a custom name, so we have
                 // to assume there are no custom sniffs to go with this otherwise
                 // we'd be recursing through directories on every run, even if
                 // we don't need to.
                 self::$standardDir = $standard;
             }
             $standard = (string) $ruleset['name'];
         } else {
             self::$standardDir = realpath(dirname(__FILE__) . '/CodeSniffer/Standards/' . $standard);
             if (is_dir(self::$standardDir) === false) {
                 // This isn't looking good. Let's see if this
                 // is a relative path to a custom standard.
                 $path = realpath(PHPCS_CWD . '/' . $standard);
                 if (is_dir($path) === true) {
                     // This is a relative path to a custom standard.
                     self::$standardDir = $path;
                     $standard = basename($standard);
                 } else {
                     if (is_file($path) === true) {
                         // Might be a custom ruleset file.
                         $ruleset = simplexml_load_file($path);
                         if ($ruleset === false) {
                             throw new PHP_CodeSniffer_Exception("Ruleset {$path} is not valid");
                         }
                         // See comments in ELSE IF condition above for why we do this.
                         if (basename($path) === 'ruleset.xml') {
                             self::$standardDir = dirname($path);
                         } else {
                             self::$standardDir = $path;
                         }
                         $standard = (string) $ruleset['name'];
                     }
                 }
             }
         }
     }
     //end if
     $files = $this->getSniffFiles(self::$standardDir, $standard);
     if (empty($sniffs) === false) {
         // Convert the allowed sniffs to lower case so
         // they are easier to check.
         foreach ($sniffs as &$sniff) {
             $sniff = strtolower($sniff);
         }
     }
     $listeners = array();
     foreach ($files as $file) {
         // Work out where the position of /StandardName/Sniffs/... is
         // so we can determine what the class will be called.
         $sniffPos = strrpos($file, DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR);
         if ($sniffPos === false) {
             continue;
         }
         $slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
         if ($slashPos === false) {
             continue;
         }
         $className = substr($file, $slashPos + 1);
         $className = substr($className, 0, -4);
         $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
//.........這裏部分代碼省略.........
開發者ID:natmchugh,項目名稱:PHP_CodeSniffer,代碼行數:101,代碼來源:CodeSniffer.php


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