Chris@0
|
1 <?php
|
Chris@0
|
2 namespace Composer\Installers;
|
Chris@0
|
3
|
Chris@0
|
4 use Composer\IO\IOInterface;
|
Chris@0
|
5 use Composer\Installer\LibraryInstaller;
|
Chris@0
|
6 use Composer\Package\PackageInterface;
|
Chris@0
|
7 use Composer\Repository\InstalledRepositoryInterface;
|
Chris@0
|
8
|
Chris@0
|
9 class Installer extends LibraryInstaller
|
Chris@0
|
10 {
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Package types to installer class map
|
Chris@0
|
13 *
|
Chris@0
|
14 * @var array
|
Chris@0
|
15 */
|
Chris@0
|
16 private $supportedTypes = array(
|
Chris@0
|
17 'aimeos' => 'AimeosInstaller',
|
Chris@0
|
18 'asgard' => 'AsgardInstaller',
|
Chris@0
|
19 'attogram' => 'AttogramInstaller',
|
Chris@0
|
20 'agl' => 'AglInstaller',
|
Chris@0
|
21 'annotatecms' => 'AnnotateCmsInstaller',
|
Chris@0
|
22 'bitrix' => 'BitrixInstaller',
|
Chris@0
|
23 'bonefish' => 'BonefishInstaller',
|
Chris@0
|
24 'cakephp' => 'CakePHPInstaller',
|
Chris@0
|
25 'chef' => 'ChefInstaller',
|
Chris@0
|
26 'ccframework' => 'ClanCatsFrameworkInstaller',
|
Chris@0
|
27 'cockpit' => 'CockpitInstaller',
|
Chris@0
|
28 'codeigniter' => 'CodeIgniterInstaller',
|
Chris@0
|
29 'concrete5' => 'Concrete5Installer',
|
Chris@0
|
30 'craft' => 'CraftInstaller',
|
Chris@0
|
31 'croogo' => 'CroogoInstaller',
|
Chris@0
|
32 'dokuwiki' => 'DokuWikiInstaller',
|
Chris@0
|
33 'dolibarr' => 'DolibarrInstaller',
|
Chris@0
|
34 'decibel' => 'DecibelInstaller',
|
Chris@0
|
35 'drupal' => 'DrupalInstaller',
|
Chris@0
|
36 'elgg' => 'ElggInstaller',
|
Chris@0
|
37 'eliasis' => 'EliasisInstaller',
|
Chris@0
|
38 'ee3' => 'ExpressionEngineInstaller',
|
Chris@0
|
39 'ee2' => 'ExpressionEngineInstaller',
|
Chris@0
|
40 'ezplatform' => 'EzPlatformInstaller',
|
Chris@0
|
41 'fuel' => 'FuelInstaller',
|
Chris@0
|
42 'fuelphp' => 'FuelphpInstaller',
|
Chris@0
|
43 'grav' => 'GravInstaller',
|
Chris@0
|
44 'hurad' => 'HuradInstaller',
|
Chris@0
|
45 'imagecms' => 'ImageCMSInstaller',
|
Chris@0
|
46 'itop' => 'ItopInstaller',
|
Chris@0
|
47 'joomla' => 'JoomlaInstaller',
|
Chris@0
|
48 'kanboard' => 'KanboardInstaller',
|
Chris@0
|
49 'kirby' => 'KirbyInstaller',
|
Chris@0
|
50 'kodicms' => 'KodiCMSInstaller',
|
Chris@0
|
51 'kohana' => 'KohanaInstaller',
|
Chris@0
|
52 'lms' => 'LanManagementSystemInstaller',
|
Chris@0
|
53 'laravel' => 'LaravelInstaller',
|
Chris@0
|
54 'lavalite' => 'LavaLiteInstaller',
|
Chris@0
|
55 'lithium' => 'LithiumInstaller',
|
Chris@0
|
56 'magento' => 'MagentoInstaller',
|
Chris@0
|
57 'mako' => 'MakoInstaller',
|
Chris@0
|
58 'maya' => 'MayaInstaller',
|
Chris@0
|
59 'mautic' => 'MauticInstaller',
|
Chris@0
|
60 'mediawiki' => 'MediaWikiInstaller',
|
Chris@0
|
61 'microweber' => 'MicroweberInstaller',
|
Chris@0
|
62 'modulework' => 'MODULEWorkInstaller',
|
Chris@0
|
63 'modxevo' => 'MODXEvoInstaller',
|
Chris@0
|
64 'moodle' => 'MoodleInstaller',
|
Chris@0
|
65 'october' => 'OctoberInstaller',
|
Chris@0
|
66 'ontowiki' => 'OntoWikiInstaller',
|
Chris@0
|
67 'oxid' => 'OxidInstaller',
|
Chris@0
|
68 'osclass' => 'OsclassInstaller',
|
Chris@0
|
69 'phpbb' => 'PhpBBInstaller',
|
Chris@0
|
70 'pimcore' => 'PimcoreInstaller',
|
Chris@0
|
71 'piwik' => 'PiwikInstaller',
|
Chris@0
|
72 'plentymarkets'=> 'PlentymarketsInstaller',
|
Chris@0
|
73 'ppi' => 'PPIInstaller',
|
Chris@0
|
74 'puppet' => 'PuppetInstaller',
|
Chris@0
|
75 'radphp' => 'RadPHPInstaller',
|
Chris@0
|
76 'phifty' => 'PhiftyInstaller',
|
Chris@0
|
77 'porto' => 'PortoInstaller',
|
Chris@0
|
78 'redaxo' => 'RedaxoInstaller',
|
Chris@0
|
79 'reindex' => 'ReIndexInstaller',
|
Chris@0
|
80 'roundcube' => 'RoundcubeInstaller',
|
Chris@0
|
81 'shopware' => 'ShopwareInstaller',
|
Chris@0
|
82 'silverstripe' => 'SilverStripeInstaller',
|
Chris@0
|
83 'smf' => 'SMFInstaller',
|
Chris@0
|
84 'sydes' => 'SyDESInstaller',
|
Chris@0
|
85 'symfony1' => 'Symfony1Installer',
|
Chris@0
|
86 'thelia' => 'TheliaInstaller',
|
Chris@0
|
87 'tusk' => 'TuskInstaller',
|
Chris@0
|
88 'typo3-cms' => 'TYPO3CmsInstaller',
|
Chris@0
|
89 'typo3-flow' => 'TYPO3FlowInstaller',
|
Chris@0
|
90 'userfrosting' => 'UserFrostingInstaller',
|
Chris@0
|
91 'vanilla' => 'VanillaInstaller',
|
Chris@0
|
92 'whmcs' => 'WHMCSInstaller',
|
Chris@0
|
93 'wolfcms' => 'WolfCMSInstaller',
|
Chris@0
|
94 'wordpress' => 'WordPressInstaller',
|
Chris@0
|
95 'yawik' => 'YawikInstaller',
|
Chris@0
|
96 'zend' => 'ZendInstaller',
|
Chris@0
|
97 'zikula' => 'ZikulaInstaller',
|
Chris@0
|
98 'prestashop' => 'PrestashopInstaller'
|
Chris@0
|
99 );
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * {@inheritDoc}
|
Chris@0
|
103 */
|
Chris@0
|
104 public function getInstallPath(PackageInterface $package)
|
Chris@0
|
105 {
|
Chris@0
|
106 $type = $package->getType();
|
Chris@0
|
107 $frameworkType = $this->findFrameworkType($type);
|
Chris@0
|
108
|
Chris@0
|
109 if ($frameworkType === false) {
|
Chris@0
|
110 throw new \InvalidArgumentException(
|
Chris@0
|
111 'Sorry the package type of this package is not yet supported.'
|
Chris@0
|
112 );
|
Chris@0
|
113 }
|
Chris@0
|
114
|
Chris@0
|
115 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
|
Chris@0
|
116 $installer = new $class($package, $this->composer, $this->getIO());
|
Chris@0
|
117
|
Chris@0
|
118 return $installer->getInstallPath($package, $frameworkType);
|
Chris@0
|
119 }
|
Chris@0
|
120
|
Chris@0
|
121 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
|
Chris@0
|
122 {
|
Chris@0
|
123 if (!$repo->hasPackage($package)) {
|
Chris@0
|
124 throw new \InvalidArgumentException('Package is not installed: '.$package);
|
Chris@0
|
125 }
|
Chris@0
|
126
|
Chris@0
|
127 $repo->removePackage($package);
|
Chris@0
|
128
|
Chris@0
|
129 $installPath = $this->getInstallPath($package);
|
Chris@0
|
130 $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
|
Chris@0
|
131 }
|
Chris@0
|
132
|
Chris@0
|
133 /**
|
Chris@0
|
134 * {@inheritDoc}
|
Chris@0
|
135 */
|
Chris@0
|
136 public function supports($packageType)
|
Chris@0
|
137 {
|
Chris@0
|
138 $frameworkType = $this->findFrameworkType($packageType);
|
Chris@0
|
139
|
Chris@0
|
140 if ($frameworkType === false) {
|
Chris@0
|
141 return false;
|
Chris@0
|
142 }
|
Chris@0
|
143
|
Chris@0
|
144 $locationPattern = $this->getLocationPattern($frameworkType);
|
Chris@0
|
145
|
Chris@0
|
146 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
|
Chris@0
|
147 }
|
Chris@0
|
148
|
Chris@0
|
149 /**
|
Chris@0
|
150 * Finds a supported framework type if it exists and returns it
|
Chris@0
|
151 *
|
Chris@0
|
152 * @param string $type
|
Chris@0
|
153 * @return string
|
Chris@0
|
154 */
|
Chris@0
|
155 protected function findFrameworkType($type)
|
Chris@0
|
156 {
|
Chris@0
|
157 $frameworkType = false;
|
Chris@0
|
158
|
Chris@0
|
159 krsort($this->supportedTypes);
|
Chris@0
|
160
|
Chris@0
|
161 foreach ($this->supportedTypes as $key => $val) {
|
Chris@0
|
162 if ($key === substr($type, 0, strlen($key))) {
|
Chris@0
|
163 $frameworkType = substr($type, 0, strlen($key));
|
Chris@0
|
164 break;
|
Chris@0
|
165 }
|
Chris@0
|
166 }
|
Chris@0
|
167
|
Chris@0
|
168 return $frameworkType;
|
Chris@0
|
169 }
|
Chris@0
|
170
|
Chris@0
|
171 /**
|
Chris@0
|
172 * Get the second part of the regular expression to check for support of a
|
Chris@0
|
173 * package type
|
Chris@0
|
174 *
|
Chris@0
|
175 * @param string $frameworkType
|
Chris@0
|
176 * @return string
|
Chris@0
|
177 */
|
Chris@0
|
178 protected function getLocationPattern($frameworkType)
|
Chris@0
|
179 {
|
Chris@0
|
180 $pattern = false;
|
Chris@0
|
181 if (!empty($this->supportedTypes[$frameworkType])) {
|
Chris@0
|
182 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
|
Chris@0
|
183 /** @var BaseInstaller $framework */
|
Chris@0
|
184 $framework = new $frameworkClass(null, $this->composer, $this->getIO());
|
Chris@0
|
185 $locations = array_keys($framework->getLocations());
|
Chris@0
|
186 $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
|
Chris@0
|
187 }
|
Chris@0
|
188
|
Chris@0
|
189 return $pattern ? : '(\w+)';
|
Chris@0
|
190 }
|
Chris@0
|
191
|
Chris@0
|
192 /**
|
Chris@0
|
193 * Get I/O object
|
Chris@0
|
194 *
|
Chris@0
|
195 * @return IOInterface
|
Chris@0
|
196 */
|
Chris@0
|
197 private function getIO()
|
Chris@0
|
198 {
|
Chris@0
|
199 return $this->io;
|
Chris@0
|
200 }
|
Chris@0
|
201 }
|