2 namespace Composer\Installers;
4 use Composer\IO\IOInterface;
5 use Composer\Installer\LibraryInstaller;
6 use Composer\Package\PackageInterface;
7 use Composer\Repository\InstalledRepositoryInterface;
9 class Installer extends LibraryInstaller
12 * Package types to installer class map
16 private $supportedTypes = array(
17 'aimeos' => 'AimeosInstaller',
18 'asgard' => 'AsgardInstaller',
19 'attogram' => 'AttogramInstaller',
20 'agl' => 'AglInstaller',
21 'annotatecms' => 'AnnotateCmsInstaller',
22 'bitrix' => 'BitrixInstaller',
23 'bonefish' => 'BonefishInstaller',
24 'cakephp' => 'CakePHPInstaller',
25 'chef' => 'ChefInstaller',
26 'ccframework' => 'ClanCatsFrameworkInstaller',
27 'cockpit' => 'CockpitInstaller',
28 'codeigniter' => 'CodeIgniterInstaller',
29 'concrete5' => 'Concrete5Installer',
30 'craft' => 'CraftInstaller',
31 'croogo' => 'CroogoInstaller',
32 'dokuwiki' => 'DokuWikiInstaller',
33 'dolibarr' => 'DolibarrInstaller',
34 'decibel' => 'DecibelInstaller',
35 'drupal' => 'DrupalInstaller',
36 'elgg' => 'ElggInstaller',
37 'ee3' => 'ExpressionEngineInstaller',
38 'ee2' => 'ExpressionEngineInstaller',
39 'fuel' => 'FuelInstaller',
40 'fuelphp' => 'FuelphpInstaller',
41 'grav' => 'GravInstaller',
42 'hurad' => 'HuradInstaller',
43 'imagecms' => 'ImageCMSInstaller',
44 'joomla' => 'JoomlaInstaller',
45 'kirby' => 'KirbyInstaller',
46 'kodicms' => 'KodiCMSInstaller',
47 'kohana' => 'KohanaInstaller',
48 'laravel' => 'LaravelInstaller',
49 'lithium' => 'LithiumInstaller',
50 'magento' => 'MagentoInstaller',
51 'mako' => 'MakoInstaller',
52 'mautic' => 'MauticInstaller',
53 'mediawiki' => 'MediaWikiInstaller',
54 'microweber' => 'MicroweberInstaller',
55 'modulework' => 'MODULEWorkInstaller',
56 'modxevo' => 'MODXEvoInstaller',
57 'moodle' => 'MoodleInstaller',
58 'october' => 'OctoberInstaller',
59 'oxid' => 'OxidInstaller',
60 'phpbb' => 'PhpBBInstaller',
61 'pimcore' => 'PimcoreInstaller',
62 'piwik' => 'PiwikInstaller',
63 'plentymarkets'=> 'PlentymarketsInstaller',
64 'ppi' => 'PPIInstaller',
65 'puppet' => 'PuppetInstaller',
66 'radphp' => 'RadPHPInstaller',
67 'phifty' => 'PhiftyInstaller',
68 'redaxo' => 'RedaxoInstaller',
69 'reindex' => 'ReIndexInstaller',
70 'roundcube' => 'RoundcubeInstaller',
71 'shopware' => 'ShopwareInstaller',
72 'silverstripe' => 'SilverStripeInstaller',
73 'smf' => 'SMFInstaller',
74 'symfony1' => 'Symfony1Installer',
75 'thelia' => 'TheliaInstaller',
76 'tusk' => 'TuskInstaller',
77 'typo3-cms' => 'TYPO3CmsInstaller',
78 'typo3-flow' => 'TYPO3FlowInstaller',
79 'vanilla' => 'VanillaInstaller',
80 'whmcs' => 'WHMCSInstaller',
81 'wolfcms' => 'WolfCMSInstaller',
82 'wordpress' => 'WordPressInstaller',
83 'yawik' => 'YawikInstaller',
84 'zend' => 'ZendInstaller',
85 'zikula' => 'ZikulaInstaller',
86 'prestashop' => 'PrestashopInstaller'
92 public function getInstallPath(PackageInterface $package)
94 $type = $package->getType();
95 $frameworkType = $this->findFrameworkType($type);
97 if ($frameworkType === false) {
98 throw new \InvalidArgumentException(
99 'Sorry the package type of this package is not yet supported.'
103 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
104 $installer = new $class($package, $this->composer, $this->getIO());
106 return $installer->getInstallPath($package, $frameworkType);
109 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
111 if (!$repo->hasPackage($package)) {
112 throw new \InvalidArgumentException('Package is not installed: '.$package);
115 $repo->removePackage($package);
117 $installPath = $this->getInstallPath($package);
118 $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
124 public function supports($packageType)
126 $frameworkType = $this->findFrameworkType($packageType);
128 if ($frameworkType === false) {
132 $locationPattern = $this->getLocationPattern($frameworkType);
134 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
138 * Finds a supported framework type if it exists and returns it
140 * @param string $type
143 protected function findFrameworkType($type)
145 $frameworkType = false;
147 krsort($this->supportedTypes);
149 foreach ($this->supportedTypes as $key => $val) {
150 if ($key === substr($type, 0, strlen($key))) {
151 $frameworkType = substr($type, 0, strlen($key));
156 return $frameworkType;
160 * Get the second part of the regular expression to check for support of a
163 * @param string $frameworkType
166 protected function getLocationPattern($frameworkType)
169 if (!empty($this->supportedTypes[$frameworkType])) {
170 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
171 /** @var BaseInstaller $framework */
172 $framework = new $frameworkClass(null, $this->composer, $this->getIO());
173 $locations = array_keys($framework->getLocations());
174 $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
177 return $pattern ? : '(\w+)';
183 * @return IOInterface
185 private function getIO()