getPath() public static method

Returns the path for a specific class.
public static getPath ( string $class ) : string
$class string Class path to get
return string
示例#1
0
 /**
  * Autoload function for HTML Purifier
  * @param $class Class to load
  */
 public static function autoload($class)
 {
     $file = HTMLPurifier_Bootstrap::getPath($class);
     if (!$file) {
         return false;
     }
     require_once HTMLPURIFIER_PREFIX . '/' . $file;
     return true;
 }
示例#2
0
 /**
  * Autoload function for HTML Purifier
  * @param string $class Class to load
  * @return bool
  */
 public static function autoload($class)
 {
     $file = HTMLPurifier_Bootstrap::getPath($class);
     if (!$file) {
         return false;
     }
     // Technically speaking, it should be ok and more efficient to
     // just do 'require', but Antonio Parraga reports that with
     // Zend extensions such as Zend debugger and APC, this invariant
     // may be broken.  Since we have efficient alternatives, pay
     // the cost here and avoid the bug.
     require_once HTMLPURIFIER_PREFIX . '/' . $file;
     return true;
 }
/**
 * Returns a lookup array of dependencies for a file.
 *
 * @note This function expects that format $name extends $parent on one line
 *
 * @param $file
 *      File to check dependencies of.
 * @return
 *      Lookup array of files the file is dependent on, sorted accordingly.
 */
function get_dependency_lookup($file)
{
    static $cache = array();
    if (isset($cache[$file])) {
        return $cache[$file];
    }
    if (!file_exists($file)) {
        echo "File doesn't exist: {$file}\n";
        return array();
    }
    $fh = fopen($file, 'r');
    $deps = array();
    while (!feof($fh)) {
        $line = fgets($fh);
        if (strncmp('class', $line, 5) === 0) {
            // The implementation here is fragile and will break if we attempt
            // to use interfaces. Beware!
            list(, $parent) = explode(' extends ', trim($line, ' {' . "\n\r"), 2);
            if (empty($parent)) {
                break;
            }
            $dep_file = HTMLPurifier_Bootstrap::getPath($parent);
            if (!$dep_file) {
                break;
            }
            $deps[$dep_file] = true;
            break;
        }
    }
    fclose($fh);
    foreach (array_keys($deps) as $file) {
        // Extra dependencies must come *before* base dependencies
        $deps = get_dependency_lookup($file) + $deps;
    }
    $cache[$file] = $deps;
    return $deps;
}