コード例 #1
0
    private static $classDictionary = array('Smarty' => 'lib/Smarty/libs/Smarty.class.php', 'cache' => 'lib/cache.php', 'PasswordManager' => 'lib/passwordManager.php', 'GeoKretyApi' => 'GeoKretyAPI.php', 'GetRegions' => 'GetRegions.php', 'myninc' => 'lib/myn.inc.php', 'localCachesInc' => 'lib/local_caches.inc.php', 'powerTrailBase' => 'powerTrail/powerTrailBase.php', 'powerTrailController' => 'powerTrail/powerTrailController.php', 'sendEmail' => 'powerTrail/sendEmail.php', 'Kint' => 'lib/kint/Kint.class.php', 'userInputFilter' => 'lib/userInputFilters/userInputFilter.php', 'PlotLine' => 'lib/jpgraph/src/jpgraph_plotline.php');
    public static function getClassPath($className)
    {
        $classPathArr = explode('\\', $className);
        if (isset($classPathArr[1])) {
            /* namespace solution */
            $classPath = __DIR__ . '/../';
            foreach ($classPathArr as $pathPiece) {
                $classPath .= $pathPiece . '/';
            }
            $classPath = substr($classPath, 0, -1) . '.php';
            return $classPath;
        }
        if (isset(self::$classDictionary[$className])) {
            return __DIR__ . '/../' . self::$classDictionary[$className];
        } else {
            trigger_error("Classpath can't find: {$className}", E_USER_WARNING);
            return null;
        }
    }
}
spl_autoload_register(function ($className) {
    if (strpos($className, 'Smarty_') !== false) {
        /* ignore smary class autoloading */
        return;
    }
    $classFile = ClassPathDictionary::getClassPath($className);
    if (!is_null($classFile)) {
        include_once $classFile;
    }
});
コード例 #2
0
     *
     * use this method if using namespace is not possible any reason
     *
     * example:
     * 'className' => 'path/to/filename.php',
     *
     * !!! please preserve alphabetical order. !!!
     */
    private static $classDictionary = array('Smarty' => 'lib/Smarty/libs/Smarty.class.php', 'cache' => 'lib/cache.php', 'dataBase' => 'lib/Database/Db.php', 'MyDB' => 'lib/Database/MyDB.php', 'PasswordManager' => 'lib/passwordManager.php', 'GeoKretyApi' => 'GeoKretyAPI.php', 'GetRegions' => 'GetRegions.php', 'myninc' => 'lib/myn.inc.php', 'localCachesInc' => 'lib/local_caches.inc.php', 'powerTrailBase' => 'powerTrail/powerTrailBase.php', 'powerTrailController' => 'powerTrail/powerTrailController.php', 'sendEmail' => 'powerTrail/sendEmail.php', 'Kint' => 'lib/kint/Kint.class.php', 'userInputFilter' => 'lib/userInputFilters/userInputFilter.php');
    public static function getClassPath($className)
    {
        $classPathArr = explode('\\', $className);
        if (isset($classPathArr[1])) {
            /* namespace solution */
            $classPath = __DIR__ . '/../';
            foreach ($classPathArr as $pathPiece) {
                $classPath .= $pathPiece . '/';
            }
            $classPath = substr($classPath, 0, -1) . '.php';
            return $classPath;
        }
        return __DIR__ . '/../' . self::$classDictionary[$className];
    }
}
spl_autoload_register(function ($className) {
    if (strpos($className, 'Smarty_') !== false) {
        /* ignore smary class autoloading */
        return;
    }
    include_once ClassPathDictionary::getClassPath($className);
});