From c0aad84d8bbb1d4041036e99354ba429552af999 Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Sat, 14 Dec 2013 16:33:59 +0100 Subject: [PATCH] Validation to make the combination of target-dir with psr-4 illegal. --- src/Composer/Autoload/AutoloadGenerator.php | 16 ++++++++++++++++ .../Package/Loader/ValidatingArrayLoader.php | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 3a0d6c2c2..86a39e47f 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -259,6 +259,7 @@ EOF; if ($package instanceof AliasPackage) { continue; } + $this->validatePackage($package); $packageMap[] = array( $package, @@ -269,6 +270,21 @@ EOF; return $packageMap; } + /** + * @param PackageInterface $package + * + * @throws \Exception + * Throws an exception, if the package has illegal settings. + */ + protected function validatePackage(PackageInterface $package) { + $autoload = $package->getAutoload(); + if (!empty($autoload['psr-4']) && null !== $package->getTargetDir()) { + $name = $package->getName(); + $package->getTargetDir(); + throw new \Exception("The ['autoload']['psr-4'] setting is incompatible with the ['target-dir'] setting, in package '$name'."); + } + } + /** * Compiles an ordered list of namespace => path mappings * diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 6d71a09bd..f93e10bf1 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -189,6 +189,13 @@ class ValidatingArrayLoader implements LoaderInterface } } + if (!empty($this->config['autoload']['psr-4']) && !empty($this->config['target-dir'])) { + $this->errors[] = "The ['autoload']['psr-4'] setting is incompatible with the ['target-dir'] setting."; + // Unset the psr-4 setting, since unsetting target-dir might + // interfere with other settings. + unset($this->config['autoload']['psr-4']); + } + // TODO validate dist // TODO validate source