From 2461657c2817807b869128347b0b295a6b91cca9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 22 Jul 2016 11:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E7=9A=84=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E6=B3=A8=E5=85=A5?= =?UTF-8?q?Request=E4=B9=8B=E5=A4=96=E7=9A=84=E5=AF=B9=E8=B1=A1=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 5 +++-- library/think/Loader.php | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index ebc3a776..e41bd9f3 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -238,8 +238,9 @@ class App foreach ($params as $param) { $name = $param->getName(); $class = $param->getClass(); - if ($class && 'think\Request' == $class->getName()) { - $args[] = Request::instance(); + if ($class) { + $className = $class->getName(); + $args[] = method_exists($className, 'instance') ? $className::instance() : new $className(); } elseif (1 == $type && !empty($vars)) { $args[] = array_shift($vars); } elseif (0 == $type && isset($vars[$name])) { diff --git a/library/think/Loader.php b/library/think/Loader.php index ed206107..9451db66 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -99,7 +99,7 @@ class Loader if (false !== $pos = strrpos($class, '\\')) { // namespaced class name $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DS); + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DS); } else { // PEAR-like class name $logicalPathPsr0 = strtr($class, '_', DS) . EXT; @@ -155,13 +155,13 @@ class Loader if (!$prefix) { if ($prepend) { self::$fallbackDirsPsr0 = array_merge( - (array)$paths, + (array) $paths, self::$fallbackDirsPsr0 ); } else { self::$fallbackDirsPsr0 = array_merge( self::$fallbackDirsPsr0, - (array)$paths + (array) $paths ); } @@ -170,24 +170,23 @@ class Loader $first = $prefix[0]; if (!isset(self::$prefixesPsr0[$first][$prefix])) { - self::$prefixesPsr0[$first][$prefix] = (array)$paths; + self::$prefixesPsr0[$first][$prefix] = (array) $paths; return; } if ($prepend) { self::$prefixesPsr0[$first][$prefix] = array_merge( - (array)$paths, + (array) $paths, self::$prefixesPsr0[$first][$prefix] ); } else { self::$prefixesPsr0[$first][$prefix] = array_merge( self::$prefixesPsr0[$first][$prefix], - (array)$paths + (array) $paths ); } } - // 添加Psr4空间 private static function addPsr4($prefix, $paths, $prepend = false) { @@ -195,13 +194,13 @@ class Loader // Register directories for the root namespace. if ($prepend) { self::$fallbackDirsPsr4 = array_merge( - (array)$paths, + (array) $paths, self::$fallbackDirsPsr4 ); } else { self::$fallbackDirsPsr4 = array_merge( self::$fallbackDirsPsr4, - (array)$paths + (array) $paths ); } } elseif (!isset(self::$prefixDirsPsr4[$prefix])) { @@ -211,23 +210,22 @@ class Loader throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } self::$prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - self::$prefixDirsPsr4[$prefix] = (array)$paths; + self::$prefixDirsPsr4[$prefix] = (array) $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. self::$prefixDirsPsr4[$prefix] = array_merge( - (array)$paths, + (array) $paths, self::$prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. self::$prefixDirsPsr4[$prefix] = array_merge( self::$prefixDirsPsr4[$prefix], - (array)$paths + (array) $paths ); } } - // 注册命名空间别名 public static function addNamespaceAlias($namespace, $original = '') { @@ -308,8 +306,8 @@ class Loader public static function import($class, $baseUrl = '', $ext = EXT) { static $_file = []; - $key = $class . $baseUrl; - $class = str_replace(['.', '#'], [DS, '.'], $class); + $key = $class . $baseUrl; + $class = str_replace(['.', '#'], [DS, '.'], $class); if (isset($_file[$key])) { return true; } @@ -548,4 +546,4 @@ function __include_file($file) function __require_file($file) { return require $file; -} \ No newline at end of file +}