-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom installer for drupal-console-library type (#22)
- Loading branch information
1 parent
7a943bf
commit ad8e52d
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace Drupal\Console\Composer\Plugin; | ||
|
||
use Composer\Installers\BaseInstaller; | ||
|
||
/** | ||
* Class DemoInstaller | ||
* | ||
* @package Composer\Installers | ||
*/ | ||
class DrupalConsoleInstaller extends BaseInstaller | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $locations = array( | ||
'console-library' => 'vendor/drupal/{$name}/', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Drupal\Console\Composer\Plugin; | ||
|
||
use Composer\IO\IOInterface; | ||
use Composer\Package\PackageInterface; | ||
use Composer\Installers\Installer as BaseInstaller; | ||
|
||
class Installer extends BaseInstaller | ||
{ | ||
|
||
/** | ||
* Package types to installer class map | ||
* | ||
* @var array | ||
*/ | ||
private $supportedTypes = array( | ||
'drupal' => 'DrupalConsoleInstaller' | ||
); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getInstallPath(PackageInterface $package) | ||
{ | ||
$type = $package->getType(); | ||
$frameworkType = $this->findFrameworkType($type); | ||
|
||
if ($frameworkType === false) { | ||
throw new \InvalidArgumentException( | ||
'Sorry the package type of this package is not yet supported.' | ||
); | ||
} | ||
|
||
$class = 'Drupal\\Console\\Composer\\Plugin\\' . $this->supportedTypes[$frameworkType]; | ||
$installer = new $class($package, $this->composer, $this->getIO()); | ||
|
||
return $installer->getInstallPath($package, $frameworkType); | ||
} | ||
|
||
/** | ||
* Get the second part of the regular expression to check for support of a | ||
* package type | ||
* | ||
* @param string $frameworkType | ||
* @return string | ||
*/ | ||
protected function getLocationPattern($frameworkType) | ||
{ | ||
$pattern = false; | ||
if (!empty($this->supportedTypes[$frameworkType])) { | ||
$frameworkClass = 'Drupal\\Console\\Composer\\Plugin\\' . $this->supportedTypes[$frameworkType]; | ||
/** @var BaseInstaller $framework */ | ||
$framework = new $frameworkClass(null, $this->composer, $this->getIO()); | ||
$locations = array_keys($framework->getLocations()); | ||
$pattern = $locations ? '(' . implode('|', $locations) . ')' : false; | ||
} | ||
|
||
return $pattern ? : '(\w+)'; | ||
} | ||
|
||
/** | ||
* Get I/O object | ||
* | ||
* @return IOInterface | ||
*/ | ||
private function getIO() | ||
{ | ||
return $this->io; | ||
} | ||
} |