From 36dd725a88ec032e74bfb0bae0befe953933fb8f Mon Sep 17 00:00:00 2001 From: Ben Bieker Date: Thu, 17 Nov 2011 15:19:58 +0100 Subject: [PATCH] It is possible to set an "install-dir" option for a package now This let's you completely customize the path needed for your custom package. So you can specify paths directly on top level and are not forced to install your packages under the vendor/ directory. Example: { "name": "my-project", "version": "1.0.0", "repositories": { "MyRepo": { "package": { "name": "mypackage", "version": "1.0", "install-dir": "lib/src/mypackage" "source": { "url": "https://github.com/awesomepackages/mypackage.git", "type": "git", "reference": "some-tag" } } } }, "require": { "mypackage" : "1.0" } } --- src/Composer/Installer/LibraryInstaller.php | 5 +++++ src/Composer/Package/BasePackage.php | 11 +++++++++++ src/Composer/Package/Loader/ArrayLoader.php | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 898c4a6b9..727e84c85 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -123,6 +123,11 @@ class LibraryInstaller implements InstallerInterface */ public function getInstallPath(PackageInterface $package) { + $installDir = $package->getInstallDir(); + if (isset($installDir)) + { + return $installDir; + } $targetDir = $package->getTargetDir(); return ($this->directory ? $this->directory.'/' : '') . $package->getName() . ($targetDir ? '/'.$targetDir : ''); } diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 786c58ae5..c22b3fdab 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -27,6 +27,7 @@ abstract class BasePackage implements PackageInterface protected $prettyName; protected $repository; protected $id; + protected $installDir; /** * All descendants' constructors should call this parent constructor @@ -92,6 +93,16 @@ abstract class BasePackage implements PackageInterface return $this->id; } + public function setInstallDir($dir) + { + $this->installDir = $dir; + } + + public function getInstallDir() + { + return $this->installDir; + } + /** * Checks if the package matches the given constraint directly or through * provided or replaced packages diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 4977763b8..51e0729e3 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -53,6 +53,10 @@ class ArrayLoader $package->setTargetDir($config['target-dir']); } + if (isset($config['install-dir'])) { + $package->setInstallDir($config['install-dir']); + } + if (isset($config['repositories'])) { $repositories = array(); foreach ($config['repositories'] as $repoName => $repo) {