123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php namespace System;
- class Loader {
-
- public static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
-
- public static $aliases = array();
-
- public static $modules = array();
-
- public static function bootstrap()
- {
- static::$aliases = Config::get('aliases');
- static::$modules = Config::get('application.modules');
- }
-
- public static function load($class)
- {
- $file = strtolower(str_replace('\\', '/', $class));
- if (array_key_exists($class, static::$aliases))
- {
- return class_alias(static::$aliases[$class], $class);
- }
- ( ! static::load_from_registered($file)) or static::load_from_module($file);
- }
-
- private static function load_from_registered($file)
- {
- foreach (static::$paths as $directory)
- {
- if (file_exists($path = $directory.$file.EXT))
- {
- require $path;
- return true;
- }
- }
- return false;
- }
-
- private static function load_from_module($file)
- {
-
-
- $module = substr($file, 0, strpos($file, '/'));
- if (in_array($module, static::$modules))
- {
- $module = MODULE_PATH.$module.'/';
-
-
-
-
-
- $file = substr($file, strpos($file, '/') + 1);
- foreach (array($module.'models', $module.'libraries') as $directory)
- {
- if (file_exists($path = $directory.'/'.$file.EXT)) return require $path;
- }
- }
- }
-
- public static function register($path)
- {
- static::$paths[] = rtrim($path, '/').'/';
- }
- }
|