本文整理汇总了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);
//.........这里部分代码省略.........