Просмотр исходного кода

Add support for mapping a namespace prefix onto many dirs in the autoload config

Jordi Boggiano 14 лет назад
Родитель
Сommit
30cfb69739

+ 8 - 0
doc/04-schema.md

@@ -204,6 +204,14 @@ Example:
     }
     }
 
 
 Optional, but it is highly recommended that you follow PSR-0 and use this.
 Optional, but it is highly recommended that you follow PSR-0 and use this.
+If you need to search for a same namespace prefix in multiple directories,
+you can specify them as an array as such:
+
+    {
+        "autoload": {
+            "psr-0": { "Monolog": ["src/", "lib/"] }
+        }
+    }
 
 
 You can use the classmap generation support to define autoloading for all libraries
 You can use the classmap generation support to define autoloading for all libraries
 that do not follow "PSR-0". To configure this you specify all directories
 that do not follow "PSR-0". To configure this you specify all directories

+ 1 - 1
res/composer-schema.json

@@ -125,7 +125,7 @@
             "properties": {
             "properties": {
                 "psr-0": {
                 "psr-0": {
                     "type": "object",
                     "type": "object",
-                    "description": "This is a hash of namespaces (keys) and the directories they can be found into (values) by the autoloader.",
+                    "description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.",
                     "additionalProperties": true
                     "additionalProperties": true
                 },
                 },
                 "classmap": {
                 "classmap": {

+ 4 - 3
src/Composer/Autoload/AutoloadGenerator.php

@@ -172,11 +172,12 @@ EOF;
             }
             }
 
 
             foreach ($package->getAutoload() as $type => $mapping) {
             foreach ($package->getAutoload() as $type => $mapping) {
-                foreach ($mapping as $namespace => $path) {
-                    $autoloads[$type][$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
+                foreach ($mapping as $namespace => $paths) {
+                    foreach ((array) $paths as $path) {
+                        $autoloads[$type][$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
+                    }
                 }
                 }
             }
             }
-
         }
         }
 
 
         foreach ($autoloads as $type => $maps) {
         foreach ($autoloads as $type => $maps) {

+ 1 - 1
tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

@@ -77,7 +77,7 @@ class AutoloadGeneratorTest extends TestCase
     {
     {
         $package = new MemoryPackage('a', '1.0', '1.0');
         $package = new MemoryPackage('a', '1.0', '1.0');
         $package->setAutoload(array(
         $package->setAutoload(array(
-            'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
+            'psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')),
             'classmap' => array('.composersrc/'),
             'classmap' => array('.composersrc/'),
         ));
         ));
 
 

+ 1 - 1
tests/Composer/Test/Autoload/Fixtures/autoload_main.php

@@ -7,5 +7,5 @@ $baseDir = dirname($vendorDir);
 
 
 return array(
 return array(
     'Main' => $baseDir . '/src/',
     'Main' => $baseDir . '/src/',
-    'Lala' => $baseDir . '/src/',
+    'Lala' => array($baseDir . '/src/', $baseDir . '/lib/'),
 );
 );