1
0
Fork 0

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

pull/509/merge
Jordi Boggiano 2012-03-28 17:09:07 +02:00
parent f7affa21b0
commit 30cfb69739
5 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -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": {

View File

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

View File

@ -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/'),
));

View File

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