PHP_CodeSniffer::autoload PHP Method

autoload() public static method

Autoload static method for loading classes and interfaces.
public static autoload ( string $className ) : void
$className string The name of the class or interface.
return void
    public static function autoload($className)
    {
        if (substr($className, 0, 4) === 'PHP_') {
            $newClassName = substr($className, 4);
        } else {
            $newClassName = $className;
        }
        $path = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $newClassName) . '.php';
        if (is_file(dirname(__FILE__) . DIRECTORY_SEPARATOR . $path) === true) {
            // Check standard file locations based on class name.
            include dirname(__FILE__) . DIRECTORY_SEPARATOR . $path;
            return;
        } else {
            // Check for included sniffs.
            $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths();
            foreach ($installedPaths as $installedPath) {
                if (is_file($installedPath . DIRECTORY_SEPARATOR . $path) === true) {
                    include $installedPath . DIRECTORY_SEPARATOR . $path;
                    return;
                }
            }
            // Check standard file locations based on the loaded rulesets.
            foreach (self::$rulesetDirs as $rulesetDir) {
                if (is_file(dirname($rulesetDir) . DIRECTORY_SEPARATOR . $path) === true) {
                    include_once dirname($rulesetDir) . DIRECTORY_SEPARATOR . $path;
                    return;
                }
            }
        }
        //end if
        // Everything else.
        @(include $path);
    }

Usage Example

Esempio n. 1
0
 /**
  * Autoload static method for loading classes and interfaces.
  *
  * @param string $className The name of the class or interface.
  *
  * @return void
  */
 public static function autoload($className)
 {
     if (substr($className, 0, 5) === 'SQLI_') {
         $newClassName = substr($className, 5);
     } else {
         $newClassName = $className;
     }
     $path = str_replace('_', '/', $newClassName) . '.php';
     if (is_file(dirname(__FILE__) . '/' . $path)) {
         // Check standard file locations based on class name.
         include dirname(__FILE__) . '/' . $path;
     } else {
         if (is_file(dirname(__FILE__) . '/CodeSniffer/Standards/' . $path)) {
             // Check for included sniffs in SQLI
             include dirname(__FILE__) . '/CodeSniffer/Standards/' . $path;
         } else {
             parent::autoload($className);
         }
     }
 }