123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace daswork;
- class Loader
- {
-
-
- protected static $map = [];
-
- protected static $namespaceAilas = [];
-
-
-
- private static $namespaces = [];
-
- private static $classMaps = [];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private static function autoload($class)
- {
- if (in_array($class, self::$classMaps)) {
- return true;
- }
-
- if ($file = self::findFile($class)) {
-
- if (IS_WIN && pathinfo($file, PATHINFO_FILENAME) != pathinfo(realpath($file), PATHINFO_FILENAME)) {
- return false;
- }
- __include_file($file);
- self::$classMaps[] = $class;
- return true;
- }
- }
-
- public static function findFile($class)
- {
- $namespace = \dirname($class);
-
- if (isset(self::$namespaces[$namespace])) {
- $file = self::$namespaces[$namespace] . basename($class) . EXT;
- return $file;
- }
-
- $model = substr($class,0,strpos($class, '\\'));
-
- if ($model=='app') {
- $file = APP_PATH . DS. str_replace('\\', DS, substr($class,strpos($class, '\\') + 1)) . EXT;
-
- return $file;
- }
- }
-
- public static function register($autoload = '')
- {
- spl_autoload_register($autoload ?: 'daswork\\Loader::autoload', true, true);
- self::$namespaces = [
- 'daswork' => CORE_PATH,
- 'daswork\lib' => CORE_PATH . 'lib' . DS
- ];
- }
- }
- * 作用范围隔离
- *
- * @param $file
- * @return mixed
- */
- function __include_file($file)
- {
- return include $file;
- }
- function __require_file($file)
- {
- return require $file;
- }
|