Skip to content

Commit

Permalink
refactor installer using getInstallPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
lunika committed Sep 1, 2014
1 parent 6b3f1ae commit 7926e18
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
45 changes: 26 additions & 19 deletions src/Thelia/Composer/TheliaInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;


/**
* Class TheliaInstaller
* @package Thelia\Composer
Expand All @@ -24,34 +23,42 @@
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;
}

/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return in_array($packageType, $this->supportedType);
return array_key_exists($packageType, $this->locations);
}
}
}
3 changes: 1 addition & 2 deletions src/Thelia/Composer/TheliaInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Thelia\Composer;


use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
Expand All @@ -28,4 +27,4 @@ public function activate(Composer $composer, IOInterface $io)
$installer = new TheliaInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
}
}
}

0 comments on commit 7926e18

Please sign in to comment.