diff --git a/doc/04-schema.md b/doc/04-schema.md index 3a250a418..56044f06f 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -438,6 +438,10 @@ use an empty prefix like: } } +#### PSR-4 + +Stub: Similar to PSR-0. + #### Classmap The `classmap` references are all combined, during install/update, into a single diff --git a/res/composer-schema.json b/res/composer-schema.json index 7b52d7733..2f3b97a84 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -203,6 +203,11 @@ "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 }, + "psr-4": { + "type": "object", + "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can be found into (values, can be arrays of paths) by the autoloader.", + "additionalProperties": true + }, "classmap": { "type": "array", "description": "This is an array of directories that contain classes to be included in the class-map generation process." diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index e3dae3ea8..3a0d6c2c2 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -310,6 +310,12 @@ EOF; } } + if (isset($autoloads['psr-4'])) { + foreach ($autoloads['psr-4'] as $namespace => $path) { + $loader->addPsr4($namespace, $path); + } + } + return $loader; } diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 97e315a5b..4b5b6ee9c 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -303,6 +303,10 @@ EOT foreach ($autoloads as $name => $path) { $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.'))); } + } elseif ($type === 'psr-4') { + foreach ($autoloads as $name => $path) { + $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.'))); + } } elseif ($type === 'classmap') { $output->writeln(implode(', ', $autoloads)); } diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index a5b6281a3..6d71a09bd 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -180,7 +180,7 @@ class ValidatingArrayLoader implements LoaderInterface } if ($this->validateArray('autoload') && !empty($this->config['autoload'])) { - $types = array('psr-0', 'classmap', 'files'); + $types = array('psr-0', 'psr-4', 'classmap', 'files'); foreach ($this->config['autoload'] as $type => $typeConfig) { if (!in_array($type, $types)) { $this->errors[] = 'autoload : invalid value ('.$type.'), must be one of '.implode(', ', $types);