/** * ディレクトリを登録します。 * * @param string $dir ディレクトリ名 */ public static function register($dir = __DIR__) { if (!is_dir($dir)) { throw new Exception("Directory Not Found. ({$dir})"); } static::$base_dir = $dir; spl_autoload_register(array(__CLASS__, '_load')); }
public static function classLoader($class) { if (static::$length == 0) { static::$base_dir = __DIR__ . '/perrich/'; static::$length = strlen(static::PREFIX); } if (strncmp(static::PREFIX, $class, static::$length) !== 0) { // no, move to the next registered autoloader return; } $relative_class = substr($class, static::$length); $relative_class = str_replace('\\', '/', $relative_class); $pos = strrpos($relative_class, '/'); if ($pos !== false) { $file = static::$base_dir . strtolower(substr($relative_class, 0, $pos)) . substr($relative_class, $pos) . '.php'; } else { $file = static::$base_dir . $relative_class . '.php'; } if (file_exists($file)) { require $file; } }