Bladeren bron

Update: Autoloader/Psr4.php

Zhu Jinhui 7 jaren geleden
bovenliggende
commit
9f7f531a37
1 gewijzigde bestanden met toevoegingen van 17 en 3 verwijderingen
  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.
      *