浏览代码

Update: Autoloader/Psr4.php

Zhu Jinhui 7 年之前
父节点
当前提交
9f7f531a37
共有 1 个文件被更改,包括 17 次插入3 次删除
  1. 17 3
      src/Autoloader/Psr4.php

+ 17 - 3
src/Autoloader/Psr4.php

@@ -399,9 +399,8 @@ class Psr4
         $file = '';
         // look through base directories for this namespace prefix
         foreach ($this->prefixes[$prefix] as $baseDir) {
-            $file = str_replace("/", DS, $baseDir
-                . str_replace('\\', DS, $relativeClass)
-                . '.php');
+            $path = $baseDir . $relativeClass. '.php';
+            $file = $this->replaceDash($path);
             // if the mapped file exists, require it
             if ($this->requireFile($file)) {
                 self::$cachedFiles[$prefix . '_' . $relativeClass] = $file;
@@ -413,6 +412,21 @@ class Psr4
         return false;
     }
 
+    /**
+     * 替换路径中多余的
+     * @param string $path 路径
+     * @return mixed
+     */
+    protected function replaceDash($path)
+    {
+        $path = str_replace('\\', DS, $path);
+        $path = str_replace('\\\\', DS, $path);
+
+        $path = str_replace('/', DS, $path);
+        $path = str_replace('//', DS, $path);
+
+        return $path;
+    }
     /**
      * If a file exists, require it from the file system.
      *