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 'eliasis' => 'EliasisInstaller',
38 'ee3' => 'ExpressionEngineInstaller',
39 'ee2' => 'ExpressionEngineInstaller',
40 'fuel' => 'FuelInstaller',
41 'fuelphp' => 'FuelphpInstaller',
42 'grav' => 'GravInstaller',
43 'hurad' => 'HuradInstaller',
44 'imagecms' => 'ImageCMSInstaller',
45 'itop' => 'ItopInstaller',
46 'joomla' => 'JoomlaInstaller',
47 'kanboard' => 'KanboardInstaller',
48 'kirby' => 'KirbyInstaller',
49 'kodicms' => 'KodiCMSInstaller',
50 'kohana' => 'KohanaInstaller',
51 'laravel' => 'LaravelInstaller',
52 'lavalite' => 'LavaLiteInstaller',
53 'lithium' => 'LithiumInstaller',
54 'magento' => 'MagentoInstaller',
55 'mako' => 'MakoInstaller',
56 'maya' => 'MayaInstaller',
57 'mautic' => 'MauticInstaller',
58 'mediawiki' => 'MediaWikiInstaller',
59 'microweber' => 'MicroweberInstaller',
60 'modulework' => 'MODULEWorkInstaller',
61 'modxevo' => 'MODXEvoInstaller',
62 'moodle' => 'MoodleInstaller',
63 'october' => 'OctoberInstaller',
64 'ontowiki' => 'OntoWikiInstaller',
65 'oxid' => 'OxidInstaller',
66 'phpbb' => 'PhpBBInstaller',
67 'pimcore' => 'PimcoreInstaller',
68 'piwik' => 'PiwikInstaller',
69 'plentymarkets'=> 'PlentymarketsInstaller',
70 'ppi' => 'PPIInstaller',
71 'puppet' => 'PuppetInstaller',
72 'radphp' => 'RadPHPInstaller',
73 'phifty' => 'PhiftyInstaller',
74 'porto' => 'PortoInstaller',
75 'redaxo' => 'RedaxoInstaller',
76 'reindex' => 'ReIndexInstaller',
77 'roundcube' => 'RoundcubeInstaller',
78 'shopware' => 'ShopwareInstaller',
79 'silverstripe' => 'SilverStripeInstaller',
80 'smf' => 'SMFInstaller',
81 'sydes' => 'SyDESInstaller',
82 'symfony1' => 'Symfony1Installer',
83 'thelia' => 'TheliaInstaller',
84 'tusk' => 'TuskInstaller',
85 'typo3-cms' => 'TYPO3CmsInstaller',
86 'typo3-flow' => 'TYPO3FlowInstaller',
87 'vanilla' => 'VanillaInstaller',
88 'whmcs' => 'WHMCSInstaller',
89 'wolfcms' => 'WolfCMSInstaller',
90 'wordpress' => 'WordPressInstaller',
91 'yawik' => 'YawikInstaller',
92 'zend' => 'ZendInstaller',
93 'zikula' => 'ZikulaInstaller',
94 'prestashop' => 'PrestashopInstaller'
100 public function getInstallPath(PackageInterface $package)
102 $type = $package->getType();
103 $frameworkType = $this->findFrameworkType($type);
105 if ($frameworkType === false) {
106 throw new \InvalidArgumentException(
107 'Sorry the package type of this package is not yet supported.'
111 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
112 $installer = new $class($package, $this->composer, $this->getIO());
114 return $installer->getInstallPath($package, $frameworkType);
117 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
119 if (!$repo->hasPackage($package)) {
120 throw new \InvalidArgumentException('Package is not installed: '.$package);
123 $repo->removePackage($package);
125 $installPath = $this->getInstallPath($package);
126 $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
132 public function supports($packageType)
134 $frameworkType = $this->findFrameworkType($packageType);
136 if ($frameworkType === false) {
140 $locationPattern = $this->getLocationPattern($frameworkType);
142 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
146 * Finds a supported framework type if it exists and returns it
148 * @param string $type
151 protected function findFrameworkType($type)
153 $frameworkType = false;
155 krsort($this->supportedTypes);
157 foreach ($this->supportedTypes as $key => $val) {
158 if ($key === substr($type, 0, strlen($key))) {
159 $frameworkType = substr($type, 0, strlen($key));
164 return $frameworkType;
168 * Get the second part of the regular expression to check for support of a
171 * @param string $frameworkType
174 protected function getLocationPattern($frameworkType)
177 if (!empty($this->supportedTypes[$frameworkType])) {
178 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
179 /** @var BaseInstaller $framework */
180 $framework = new $frameworkClass(null, $this->composer, $this->getIO());
181 $locations = array_keys($framework->getLocations());
182 $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
185 return $pattern ? : '(\w+)';
191 * @return IOInterface
193 private function getIO()