2 namespace Composer\Installers;
4 use Composer\Installer\LibraryInstaller;
5 use Composer\Package\PackageInterface;
6 use Composer\Repository\InstalledRepositoryInterface;
8 class Installer extends LibraryInstaller
11 * Package types to installer class map
15 private $supportedTypes = array(
16 'aimeos' => 'AimeosInstaller',
17 'asgard' => 'AsgardInstaller',
18 'agl' => 'AglInstaller',
19 'annotatecms' => 'AnnotateCmsInstaller',
20 'bitrix' => 'BitrixInstaller',
21 'cakephp' => 'CakePHPInstaller',
22 'chef' => 'ChefInstaller',
23 'ccframework' => 'ClanCatsFrameworkInstaller',
24 'codeigniter' => 'CodeIgniterInstaller',
25 'concrete5' => 'Concrete5Installer',
26 'craft' => 'CraftInstaller',
27 'croogo' => 'CroogoInstaller',
28 'dokuwiki' => 'DokuWikiInstaller',
29 'dolibarr' => 'DolibarrInstaller',
30 'drupal' => 'DrupalInstaller',
31 'elgg' => 'ElggInstaller',
32 'fuel' => 'FuelInstaller',
33 'fuelphp' => 'FuelphpInstaller',
34 'grav' => 'GravInstaller',
35 'hurad' => 'HuradInstaller',
36 'joomla' => 'JoomlaInstaller',
37 'kirby' => 'KirbyInstaller',
38 'kohana' => 'KohanaInstaller',
39 'laravel' => 'LaravelInstaller',
40 'lithium' => 'LithiumInstaller',
41 'magento' => 'MagentoInstaller',
42 'mako' => 'MakoInstaller',
43 'mediawiki' => 'MediaWikiInstaller',
44 'microweber' => 'MicroweberInstaller',
45 'modulework' => 'MODULEWorkInstaller',
46 'modxevo' => 'MODXEvoInstaller',
47 'moodle' => 'MoodleInstaller',
48 'october' => 'OctoberInstaller',
49 'oxid' => 'OxidInstaller',
50 'phpbb' => 'PhpBBInstaller',
51 'pimcore' => 'PimcoreInstaller',
52 'piwik' => 'PiwikInstaller',
53 'ppi' => 'PPIInstaller',
54 'puppet' => 'PuppetInstaller',
55 'redaxo' => 'RedaxoInstaller',
56 'roundcube' => 'RoundcubeInstaller',
57 'shopware' => 'ShopwareInstaller',
58 'silverstripe' => 'SilverStripeInstaller',
59 'smf' => 'SMFInstaller',
60 'symfony1' => 'Symfony1Installer',
61 'thelia' => 'TheliaInstaller',
62 'tusk' => 'TuskInstaller',
63 'typo3-cms' => 'TYPO3CmsInstaller',
64 'typo3-flow' => 'TYPO3FlowInstaller',
65 'whmcs' => 'WHMCSInstaller',
66 'wolfcms' => 'WolfCMSInstaller',
67 'wordpress' => 'WordPressInstaller',
68 'zend' => 'ZendInstaller',
69 'zikula' => 'ZikulaInstaller',
70 'prestashop' => 'PrestashopInstaller',
76 public function getInstallPath(PackageInterface $package)
78 $type = $package->getType();
79 $frameworkType = $this->findFrameworkType($type);
81 if ($frameworkType === false) {
82 throw new \InvalidArgumentException(
83 'Sorry the package type of this package is not yet supported.'
87 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
88 $installer = new $class($package, $this->composer);
90 return $installer->getInstallPath($package, $frameworkType);
93 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
95 if (!$repo->hasPackage($package)) {
96 throw new \InvalidArgumentException('Package is not installed: '.$package);
99 $repo->removePackage($package);
101 $installPath = $this->getInstallPath($package);
102 $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
108 public function supports($packageType)
110 $frameworkType = $this->findFrameworkType($packageType);
112 if ($frameworkType === false) {
116 $locationPattern = $this->getLocationPattern($frameworkType);
118 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
122 * Finds a supported framework type if it exists and returns it
124 * @param string $type
127 protected function findFrameworkType($type)
129 $frameworkType = false;
131 krsort($this->supportedTypes);
133 foreach ($this->supportedTypes as $key => $val) {
134 if ($key === substr($type, 0, strlen($key))) {
135 $frameworkType = substr($type, 0, strlen($key));
140 return $frameworkType;
144 * Get the second part of the regular expression to check for support of a
147 * @param string $frameworkType
150 protected function getLocationPattern($frameworkType)
153 if (!empty($this->supportedTypes[$frameworkType])) {
154 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
155 /** @var BaseInstaller $framework */
156 $framework = new $frameworkClass(null, $this->composer);
157 $locations = array_keys($framework->getLocations());
158 $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
161 return $pattern ? : '(\w+)';