Ver código fonte

Expose filename standardisation code.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23848 44c647ce-9c0f-0410-b52a-842ac1e357ba
rquadling 14 anos atrás
pai
commit
856e029e76
1 arquivos alterados com 27 adições e 13 exclusões
  1. 27 13
      library/Zend/Loader.php

+ 27 - 13
library/Zend/Loader.php

@@ -60,19 +60,7 @@ class Zend_Loader
             throw new Zend_Exception('Directory argument must be a string or an array');
         }
 
-        // Autodiscover the path from the class name
-        // Implementation is PHP namespace-aware, and based on
-        // Framework Interop Group reference implementation:
-        // http://groups.google.com/group/php-standards/web/psr-0-final-proposal
-        $className = ltrim($class, '\\');
-        $file      = '';
-        $namespace = '';
-        if ($lastNsPos = strripos($className, '\\')) {
-            $namespace = substr($className, 0, $lastNsPos);
-            $className = substr($className, $lastNsPos + 1);
-            $file      = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
-        }
-        $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
+        $file = self::standardiseFile($class);
 
         if (!empty($dirs)) {
             // use the autodiscovered path
@@ -326,4 +314,30 @@ class Zend_Loader
             return include $filespec ;
         }
     }
+
+    /**
+     * Standardise the filename.
+     *
+     * Convert the supplied filename into the namespace-aware standard,
+     * based on the Framework Interop Group reference implementation:
+     * http://groups.google.com/group/php-standards/web/psr-0-final-proposal
+     *
+     * The filename must be formatted as "$file.php".
+     *
+     * @param string $file - The file name to be loaded.
+     * @return string
+     */
+    public static function standardiseFile($file)
+    {
+        $fileName = ltrim($file, '\\');
+        $file      = '';
+        $namespace = '';
+        if ($lastNsPos = strripos($fileName, '\\')) {
+            $namespace = substr($fileName, 0, $lastNsPos);
+            $fileName = substr($fileName, $lastNsPos + 1);
+            $file      = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
+        }
+        $file .= str_replace('_', DIRECTORY_SEPARATOR, $fileName) . '.php';
+        return $file;    
+    }
 }