AglInstaller.php
11 years ago
AnnotateCmsInstaller.php
11 years ago
BaseInstaller.php
11 years ago
CakePHPInstaller.php
11 years ago
CodeIgniterInstaller.php
11 years ago
CroogoInstaller.php
11 years ago
DrupalInstaller.php
11 years ago
FuelInstaller.php
11 years ago
Installer.php
11 years ago
JoomlaInstaller.php
11 years ago
KohanaInstaller.php
11 years ago
LaravelInstaller.php
11 years ago
LithiumInstaller.php
11 years ago
MODULEWorkInstaller.php
11 years ago
MagentoInstaller.php
11 years ago
MakoInstaller.php
11 years ago
MediaWikiInstaller.php
11 years ago
OxidInstaller.php
11 years ago
PPIInstaller.php
11 years ago
PhpBBInstaller.php
11 years ago
SilverStripeInstaller.php
11 years ago
Symfony1Installer.php
11 years ago
TYPO3CmsInstaller.php
11 years ago
TYPO3FlowInstaller.php
11 years ago
WordPressInstaller.php
11 years ago
ZendInstaller.php
11 years ago
Installer.php
129 lines
| 1 | <?php |
| 2 | namespace Composer\Installers; |
| 3 | |
| 4 | use Composer\Installer\LibraryInstaller; |
| 5 | use Composer\Package\PackageInterface; |
| 6 | use Composer\Repository\InstalledRepositoryInterface; |
| 7 | |
| 8 | class Installer extends LibraryInstaller |
| 9 | { |
| 10 | /** |
| 11 | * Package types to installer class map |
| 12 | * |
| 13 | * @var array |
| 14 | */ |
| 15 | private $supportedTypes = array( |
| 16 | 'agl' => 'AglInstaller', |
| 17 | 'annotatecms' => 'AnnotateCmsInstaller', |
| 18 | 'cakephp' => 'CakePHPInstaller', |
| 19 | 'codeigniter' => 'CodeIgniterInstaller', |
| 20 | 'croogo' => 'CroogoInstaller', |
| 21 | 'drupal' => 'DrupalInstaller', |
| 22 | 'fuel' => 'FuelInstaller', |
| 23 | 'joomla' => 'JoomlaInstaller', |
| 24 | 'kohana' => 'KohanaInstaller', |
| 25 | 'laravel' => 'LaravelInstaller', |
| 26 | 'lithium' => 'LithiumInstaller', |
| 27 | 'magento' => 'MagentoInstaller', |
| 28 | 'mako' => 'MakoInstaller', |
| 29 | 'mediawiki' => 'MediaWikiInstaller', |
| 30 | 'modulework' => 'MODULEWorkInstaller', |
| 31 | 'oxid' => 'OxidInstaller', |
| 32 | 'phpbb' => 'PhpBBInstaller', |
| 33 | 'ppi' => 'PPIInstaller', |
| 34 | 'silverstripe' => 'SilverStripeInstaller', |
| 35 | 'symfony1' => 'Symfony1Installer', |
| 36 | 'wordpress' => 'WordPressInstaller', |
| 37 | 'zend' => 'ZendInstaller', |
| 38 | 'typo3-flow' => 'TYPO3FlowInstaller', |
| 39 | 'typo3-cms' => 'TYPO3CmsInstaller', |
| 40 | ); |
| 41 | |
| 42 | /** |
| 43 | * {@inheritDoc} |
| 44 | */ |
| 45 | public function getInstallPath(PackageInterface $package) |
| 46 | { |
| 47 | $type = $package->getType(); |
| 48 | $frameworkType = $this->findFrameworkType($type); |
| 49 | |
| 50 | if ($frameworkType === false) { |
| 51 | throw new \InvalidArgumentException( |
| 52 | 'Sorry the package type of this package is not yet supported.' |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; |
| 57 | $installer = new $class($package, $this->composer); |
| 58 | |
| 59 | return $installer->getInstallPath($package, $frameworkType); |
| 60 | } |
| 61 | |
| 62 | public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) |
| 63 | { |
| 64 | if (!$repo->hasPackage($package)) { |
| 65 | throw new \InvalidArgumentException('Package is not installed: '.$package); |
| 66 | } |
| 67 | |
| 68 | $repo->removePackage($package); |
| 69 | |
| 70 | $installPath = $this->getInstallPath($package); |
| 71 | $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * {@inheritDoc} |
| 76 | */ |
| 77 | public function supports($packageType) |
| 78 | { |
| 79 | $frameworkType = $this->findFrameworkType($packageType); |
| 80 | |
| 81 | if ($frameworkType === false) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | $locationPattern = $this->getLocationPattern($frameworkType); |
| 86 | return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Finds a supported framework type if it exists and returns it |
| 91 | * |
| 92 | * @param string $type |
| 93 | * @return string |
| 94 | */ |
| 95 | protected function findFrameworkType($type) |
| 96 | { |
| 97 | $frameworkType = false; |
| 98 | |
| 99 | foreach ($this->supportedTypes as $key => $val) { |
| 100 | if ($key === substr($type, 0, strlen($key))) { |
| 101 | $frameworkType = substr($type, 0, strlen($key)); |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return $frameworkType; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get the second part of the regular expression to check for support of a |
| 111 | * package type |
| 112 | * |
| 113 | * @param string $frameworkType |
| 114 | * @return string |
| 115 | */ |
| 116 | protected function getLocationPattern($frameworkType) |
| 117 | { |
| 118 | $pattern = false; |
| 119 | if (!empty($this->supportedTypes[$frameworkType])) { |
| 120 | $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; |
| 121 | /** @var BaseInstaller $framework */ |
| 122 | $framework = new $frameworkClass; |
| 123 | $locations = array_keys($framework->getLocations()); |
| 124 | $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; |
| 125 | } |
| 126 | return $pattern ? : '(\w+)'; |
| 127 | } |
| 128 | } |
| 129 |