Skip to content

Commit

Permalink
Support dashes within framework types
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Dec 21, 2012
1 parent a02480a commit a413672
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/Composer/Installers/BaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function __construct(PackageInterface $package, Composer $composer)
* Return the install path based on package type.
*
* @param PackageInterface $package
* @param string $frameworkType
* @return string
*/
public function getInstallPath(PackageInterface $package)
public function getInstallPath(PackageInterface $package, $frameworkType = '')
{
$type = $this->package->getType();
$packageLocation = strtolower(substr($type, strpos($type, '-') + 1));

$prettyName = $this->package->getPrettyName();
if (strpos($prettyName, '/') !== false) {
Expand All @@ -58,11 +58,12 @@ public function getInstallPath(PackageInterface $package)
}
}

if (!isset($this->locations[$packageLocation])) {
$packageType = substr($type, strlen($frameworkType) + 1);
if (!isset($this->locations[$packageType])) {
throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
}

return $this->templatePath($this->locations[$packageLocation], $availableVars);
return $this->templatePath($this->locations[$packageType], $availableVars);
}

/**
Expand Down
32 changes: 24 additions & 8 deletions src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Installer extends LibraryInstaller
'symfony1' => 'Symfony1Installer',
'wordpress' => 'WordPressInstaller',
'zend' => 'ZendInstaller',
'typo3' => 'TYPO3Installer'
'typo3-flow' => 'TYPO3FlowInstaller'
);

/**
Expand All @@ -39,29 +39,45 @@ class Installer extends LibraryInstaller
public function getInstallPath(PackageInterface $package)
{
$type = $package->getType();
$packageType = substr($type, 0, strpos($type, '-'));
$frameworkType = $this->findFrameworkType($type);

if (!isset($this->supportedTypes[$packageType])) {
if ($frameworkType === false) {
throw new \InvalidArgumentException(
'Sorry the package type of this package is not yet supported.'
);
}

$class = 'Composer\\Installers\\' . $this->supportedTypes[$packageType];
$class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
$installer = new $class($package, $this->composer);

return $installer->getInstallPath($package);
return $installer->getInstallPath($package, $frameworkType);
}

/**
* {@inheritDoc}
*/
public function supports($packageType)
{
if (preg_match('#(\w+)-(\w+)#', $packageType, $matches)) {
return isset($this->supportedTypes[$matches[1]]);
return ($this->findFrameworkType($packageType) !== false);
}

/**
* Finds a supported framework type if it exists and returns it
*
* @param string $type
* @return string
*/
protected function findFrameworkType($type)
{
$frameworkType = false;

foreach ($this->supportedTypes as $key => $val) {
if ($key === substr($type, 0, strlen($key))) {
$frameworkType = substr($type, 0, strlen($key));
break;
}
}

return false;
return $frameworkType;
}
}

0 comments on commit a413672

Please sign in to comment.