Browse Source

Validation to make the combination of target-dir with psr-4 illegal.

Andreas Hennings 11 years ago
parent
commit
c0aad84d8b

+ 16 - 0
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
      *

+ 7 - 0
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