diff --git a/doc/04-schema.md b/doc/04-schema.md index 862f70c4d..0bb286f3e 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -204,6 +204,14 @@ Example: } 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 that do not follow "PSR-0". To configure this you specify all directories diff --git a/res/composer-schema.json b/res/composer-schema.json index b435408cd..f95b4e91e 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -125,7 +125,7 @@ "properties": { "psr-0": { "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 }, "classmap": { diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 0bf0ca087..dcab0ed6c 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -172,11 +172,12 @@ EOF; } 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) { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 31be61d39..36135e3da 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -77,7 +77,7 @@ class AutoloadGeneratorTest extends TestCase { $package = new MemoryPackage('a', '1.0', '1.0'); $package->setAutoload(array( - 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'), + 'psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')), 'classmap' => array('.composersrc/'), )); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main.php index ec243e33e..cd18304db 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_main.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main.php @@ -7,5 +7,5 @@ $baseDir = dirname($vendorDir); return array( 'Main' => $baseDir . '/src/', - 'Lala' => $baseDir . '/src/', + 'Lala' => array($baseDir . '/src/', $baseDir . '/lib/'), );