From 7926e185b0e66683bb5667f7097ae9fe1b42ae1c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 1 Sep 2014 11:45:32 +0200 Subject: [PATCH] refactor installer using getInstallPath method --- src/Thelia/Composer/TheliaInstaller.php | 45 +++++++++++-------- src/Thelia/Composer/TheliaInstallerPlugin.php | 3 +- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Thelia/Composer/TheliaInstaller.php b/src/Thelia/Composer/TheliaInstaller.php index 698916d..0be1c9b 100644 --- a/src/Thelia/Composer/TheliaInstaller.php +++ b/src/Thelia/Composer/TheliaInstaller.php @@ -15,7 +15,6 @@ use Composer\Installer\LibraryInstaller; use Composer\Package\PackageInterface; - /** * Class TheliaInstaller * @package Thelia\Composer @@ -24,27 +23,35 @@ class TheliaInstaller extends LibraryInstaller { protected $locations = [ - 'module' => 'local/modules/{$name}/', - 'frontoffice-template' => 'templates/frontOffice/{$name}/', - 'backoffice-template' => 'templates/backOffice/{$name}/', - 'email-template' => 'templates/email/{$name}/', - ]; - - protected $supportedType = [ - 'thelia-module', - 'thelia-frontoffice-template', - 'thelia-backoffice-template', - 'thelia-email-template' + 'thelia-module' => 'local/modules/', + 'thelia-frontoffice-template' => 'templates/frontOffice/', + 'thelia-backoffice-template' => 'templates/backOffice/', + 'thelia-email-template' => 'templates/email/', ]; - /** - * {@inheritDoc} - */ - public function getPackageBasePath(PackageInterface $package) + public function getInstallPath(PackageInterface $package) { + $type = $package->getType(); + if (!isset($this->locations[$package->getType()])) { + throw new \InvalidArgumentException(sprintf('package type "%s" is not supported', $type)); + } + + $base = $this->locations[$type]; + + $prettyName = $package->getPrettyName(); + if (strpos($prettyName, '/') !== false) { + list($vendor, $name) = explode('/', $prettyName); + } else { + $vendor = ''; + $name = $prettyName; + } - return $this->locations[$package->getType()] . $package->getPrettyName(); + $extra = $package->getExtra(); + if (!empty($extra['installer-name'])) { + $name = $extra['installer-name']; + } + return $base . $name; } /** @@ -52,6 +59,6 @@ public function getPackageBasePath(PackageInterface $package) */ public function supports($packageType) { - return in_array($packageType, $this->supportedType); + return array_key_exists($packageType, $this->locations); } -} \ No newline at end of file +} diff --git a/src/Thelia/Composer/TheliaInstallerPlugin.php b/src/Thelia/Composer/TheliaInstallerPlugin.php index 44254e0..1d5225b 100644 --- a/src/Thelia/Composer/TheliaInstallerPlugin.php +++ b/src/Thelia/Composer/TheliaInstallerPlugin.php @@ -12,7 +12,6 @@ namespace Thelia\Composer; - use Composer\Composer; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; @@ -28,4 +27,4 @@ public function activate(Composer $composer, IOInterface $io) $installer = new TheliaInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($installer); } -} \ No newline at end of file +}