AglInstaller.php
6 months ago
AkauntingInstaller.php
6 months ago
AnnotateCmsInstaller.php
6 months ago
AsgardInstaller.php
6 months ago
AttogramInstaller.php
6 months ago
BaseInstaller.php
6 months ago
BitrixInstaller.php
6 months ago
BonefishInstaller.php
6 months ago
CakePHPInstaller.php
6 months ago
ChefInstaller.php
6 months ago
CiviCrmInstaller.php
6 months ago
ClanCatsFrameworkInstaller.php
6 months ago
CockpitInstaller.php
6 months ago
CodeIgniterInstaller.php
6 months ago
Concrete5Installer.php
6 months ago
CroogoInstaller.php
6 months ago
DecibelInstaller.php
6 months ago
DframeInstaller.php
6 months ago
DokuWikiInstaller.php
6 months ago
DolibarrInstaller.php
6 months ago
DrupalInstaller.php
6 months ago
ElggInstaller.php
6 months ago
EliasisInstaller.php
6 months ago
ExpressionEngineInstaller.php
6 months ago
EzPlatformInstaller.php
6 months ago
FuelInstaller.php
6 months ago
FuelphpInstaller.php
6 months ago
GravInstaller.php
6 months ago
HuradInstaller.php
6 months ago
ImageCMSInstaller.php
6 months ago
Installer.php
6 months ago
ItopInstaller.php
6 months ago
KanboardInstaller.php
6 months ago
KnownInstaller.php
6 months ago
KodiCMSInstaller.php
6 months ago
KohanaInstaller.php
6 months ago
LanManagementSystemInstaller.php
6 months ago
LaravelInstaller.php
6 months ago
LavaLiteInstaller.php
6 months ago
LithiumInstaller.php
6 months ago
MODULEWorkInstaller.php
6 months ago
MODXEvoInstaller.php
6 months ago
MagentoInstaller.php
6 months ago
MajimaInstaller.php
6 months ago
MakoInstaller.php
6 months ago
MantisBTInstaller.php
6 months ago
MauticInstaller.php
6 months ago
MayaInstaller.php
6 months ago
MediaWikiInstaller.php
6 months ago
MiaoxingInstaller.php
6 months ago
MicroweberInstaller.php
6 months ago
ModxInstaller.php
6 months ago
MoodleInstaller.php
6 months ago
OctoberInstaller.php
6 months ago
OntoWikiInstaller.php
6 months ago
OsclassInstaller.php
6 months ago
OxidInstaller.php
6 months ago
PPIInstaller.php
6 months ago
PantheonInstaller.php
6 months ago
PhiftyInstaller.php
6 months ago
PhpBBInstaller.php
6 months ago
PiwikInstaller.php
6 months ago
PlentymarketsInstaller.php
6 months ago
Plugin.php
6 months ago
PortoInstaller.php
6 months ago
PrestashopInstaller.php
6 months ago
ProcessWireInstaller.php
6 months ago
PuppetInstaller.php
6 months ago
PxcmsInstaller.php
6 months ago
RadPHPInstaller.php
6 months ago
ReIndexInstaller.php
6 months ago
Redaxo5Installer.php
6 months ago
RedaxoInstaller.php
6 months ago
RoundcubeInstaller.php
6 months ago
SMFInstaller.php
6 months ago
ShopwareInstaller.php
6 months ago
SilverStripeInstaller.php
6 months ago
SiteDirectInstaller.php
6 months ago
StarbugInstaller.php
6 months ago
SyDESInstaller.php
6 months ago
SyliusInstaller.php
6 months ago
TaoInstaller.php
6 months ago
TastyIgniterInstaller.php
6 months ago
TheliaInstaller.php
6 months ago
TuskInstaller.php
6 months ago
UserFrostingInstaller.php
6 months ago
VanillaInstaller.php
6 months ago
VgmcpInstaller.php
6 months ago
WHMCSInstaller.php
6 months ago
WinterInstaller.php
6 months ago
WolfCMSInstaller.php
6 months ago
WordPressInstaller.php
6 months ago
YawikInstaller.php
6 months ago
ZendInstaller.php
6 months ago
ZikulaInstaller.php
6 months ago
Installer.php
280 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Composer\Installers; |
| 4 | |
| 5 | use Composer\Composer; |
| 6 | use Composer\Installer\BinaryInstaller; |
| 7 | use Composer\Installer\LibraryInstaller; |
| 8 | use Composer\IO\IOInterface; |
| 9 | use Composer\Package\Package; |
| 10 | use Composer\Package\PackageInterface; |
| 11 | use Composer\Repository\InstalledRepositoryInterface; |
| 12 | use Composer\Util\Filesystem; |
| 13 | use React\Promise\PromiseInterface; |
| 14 | |
| 15 | class Installer extends LibraryInstaller |
| 16 | { |
| 17 | /** |
| 18 | * Package types to installer class map |
| 19 | * |
| 20 | * @var array<string, string> |
| 21 | */ |
| 22 | private $supportedTypes = array( |
| 23 | 'akaunting' => 'AkauntingInstaller', |
| 24 | 'asgard' => 'AsgardInstaller', |
| 25 | 'attogram' => 'AttogramInstaller', |
| 26 | 'agl' => 'AglInstaller', |
| 27 | 'annotatecms' => 'AnnotateCmsInstaller', |
| 28 | 'bitrix' => 'BitrixInstaller', |
| 29 | 'bonefish' => 'BonefishInstaller', |
| 30 | 'cakephp' => 'CakePHPInstaller', |
| 31 | 'chef' => 'ChefInstaller', |
| 32 | 'civicrm' => 'CiviCrmInstaller', |
| 33 | 'ccframework' => 'ClanCatsFrameworkInstaller', |
| 34 | 'cockpit' => 'CockpitInstaller', |
| 35 | 'codeigniter' => 'CodeIgniterInstaller', |
| 36 | 'concrete5' => 'Concrete5Installer', |
| 37 | 'croogo' => 'CroogoInstaller', |
| 38 | 'dframe' => 'DframeInstaller', |
| 39 | 'dokuwiki' => 'DokuWikiInstaller', |
| 40 | 'dolibarr' => 'DolibarrInstaller', |
| 41 | 'decibel' => 'DecibelInstaller', |
| 42 | 'drupal' => 'DrupalInstaller', |
| 43 | 'elgg' => 'ElggInstaller', |
| 44 | 'eliasis' => 'EliasisInstaller', |
| 45 | 'ee3' => 'ExpressionEngineInstaller', |
| 46 | 'ee2' => 'ExpressionEngineInstaller', |
| 47 | 'ezplatform' => 'EzPlatformInstaller', |
| 48 | 'fuel' => 'FuelInstaller', |
| 49 | 'fuelphp' => 'FuelphpInstaller', |
| 50 | 'grav' => 'GravInstaller', |
| 51 | 'hurad' => 'HuradInstaller', |
| 52 | 'tastyigniter' => 'TastyIgniterInstaller', |
| 53 | 'imagecms' => 'ImageCMSInstaller', |
| 54 | 'itop' => 'ItopInstaller', |
| 55 | 'kanboard' => 'KanboardInstaller', |
| 56 | 'known' => 'KnownInstaller', |
| 57 | 'kodicms' => 'KodiCMSInstaller', |
| 58 | 'kohana' => 'KohanaInstaller', |
| 59 | 'lms' => 'LanManagementSystemInstaller', |
| 60 | 'laravel' => 'LaravelInstaller', |
| 61 | 'lavalite' => 'LavaLiteInstaller', |
| 62 | 'lithium' => 'LithiumInstaller', |
| 63 | 'magento' => 'MagentoInstaller', |
| 64 | 'majima' => 'MajimaInstaller', |
| 65 | 'mantisbt' => 'MantisBTInstaller', |
| 66 | 'mako' => 'MakoInstaller', |
| 67 | 'maya' => 'MayaInstaller', |
| 68 | 'mautic' => 'MauticInstaller', |
| 69 | 'mediawiki' => 'MediaWikiInstaller', |
| 70 | 'miaoxing' => 'MiaoxingInstaller', |
| 71 | 'microweber' => 'MicroweberInstaller', |
| 72 | 'modulework' => 'MODULEWorkInstaller', |
| 73 | 'modx' => 'ModxInstaller', |
| 74 | 'modxevo' => 'MODXEvoInstaller', |
| 75 | 'moodle' => 'MoodleInstaller', |
| 76 | 'october' => 'OctoberInstaller', |
| 77 | 'ontowiki' => 'OntoWikiInstaller', |
| 78 | 'oxid' => 'OxidInstaller', |
| 79 | 'osclass' => 'OsclassInstaller', |
| 80 | 'pxcms' => 'PxcmsInstaller', |
| 81 | 'phpbb' => 'PhpBBInstaller', |
| 82 | 'piwik' => 'PiwikInstaller', |
| 83 | 'plentymarkets'=> 'PlentymarketsInstaller', |
| 84 | 'ppi' => 'PPIInstaller', |
| 85 | 'puppet' => 'PuppetInstaller', |
| 86 | 'radphp' => 'RadPHPInstaller', |
| 87 | 'phifty' => 'PhiftyInstaller', |
| 88 | 'porto' => 'PortoInstaller', |
| 89 | 'processwire' => 'ProcessWireInstaller', |
| 90 | 'quicksilver' => 'PantheonInstaller', |
| 91 | 'redaxo' => 'RedaxoInstaller', |
| 92 | 'redaxo5' => 'Redaxo5Installer', |
| 93 | 'reindex' => 'ReIndexInstaller', |
| 94 | 'roundcube' => 'RoundcubeInstaller', |
| 95 | 'shopware' => 'ShopwareInstaller', |
| 96 | 'sitedirect' => 'SiteDirectInstaller', |
| 97 | 'silverstripe' => 'SilverStripeInstaller', |
| 98 | 'smf' => 'SMFInstaller', |
| 99 | 'starbug' => 'StarbugInstaller', |
| 100 | 'sydes' => 'SyDESInstaller', |
| 101 | 'sylius' => 'SyliusInstaller', |
| 102 | 'tao' => 'TaoInstaller', |
| 103 | 'thelia' => 'TheliaInstaller', |
| 104 | 'tusk' => 'TuskInstaller', |
| 105 | 'userfrosting' => 'UserFrostingInstaller', |
| 106 | 'vanilla' => 'VanillaInstaller', |
| 107 | 'whmcs' => 'WHMCSInstaller', |
| 108 | 'winter' => 'WinterInstaller', |
| 109 | 'wolfcms' => 'WolfCMSInstaller', |
| 110 | 'wordpress' => 'WordPressInstaller', |
| 111 | 'yawik' => 'YawikInstaller', |
| 112 | 'zend' => 'ZendInstaller', |
| 113 | 'zikula' => 'ZikulaInstaller', |
| 114 | 'prestashop' => 'PrestashopInstaller' |
| 115 | ); |
| 116 | |
| 117 | /** |
| 118 | * Disables installers specified in main composer extra installer-disable |
| 119 | * list |
| 120 | */ |
| 121 | public function __construct( |
| 122 | IOInterface $io, |
| 123 | Composer $composer, |
| 124 | string $type = 'library', |
| 125 | ?Filesystem $filesystem = null, |
| 126 | ?BinaryInstaller $binaryInstaller = null |
| 127 | ) { |
| 128 | parent::__construct($io, $composer, $type, $filesystem, $binaryInstaller); |
| 129 | $this->removeDisabledInstallers(); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * {@inheritDoc} |
| 134 | */ |
| 135 | public function getInstallPath(PackageInterface $package) |
| 136 | { |
| 137 | $type = $package->getType(); |
| 138 | $frameworkType = $this->findFrameworkType($type); |
| 139 | |
| 140 | if ($frameworkType === false) { |
| 141 | throw new \InvalidArgumentException( |
| 142 | 'Sorry the package type of this package is not yet supported.' |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; |
| 147 | $installer = new $class($package, $this->composer, $this->getIO()); |
| 148 | |
| 149 | $path = $installer->getInstallPath($package, $frameworkType); |
| 150 | if (!$this->filesystem->isAbsolutePath($path)) { |
| 151 | $path = getcwd() . '/' . $path; |
| 152 | } |
| 153 | |
| 154 | return $path; |
| 155 | } |
| 156 | |
| 157 | public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) |
| 158 | { |
| 159 | $installPath = $this->getPackageBasePath($package); |
| 160 | $io = $this->io; |
| 161 | $outputStatus = function () use ($io, $installPath) { |
| 162 | $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); |
| 163 | }; |
| 164 | |
| 165 | $promise = parent::uninstall($repo, $package); |
| 166 | |
| 167 | // Composer v2 might return a promise here |
| 168 | if ($promise instanceof PromiseInterface) { |
| 169 | return $promise->then($outputStatus); |
| 170 | } |
| 171 | |
| 172 | // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async) |
| 173 | $outputStatus(); |
| 174 | |
| 175 | return null; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * {@inheritDoc} |
| 180 | */ |
| 181 | public function supports($packageType) |
| 182 | { |
| 183 | $frameworkType = $this->findFrameworkType($packageType); |
| 184 | |
| 185 | if ($frameworkType === false) { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | $locationPattern = $this->getLocationPattern($frameworkType); |
| 190 | |
| 191 | return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Finds a supported framework type if it exists and returns it |
| 196 | * |
| 197 | * @return string|false |
| 198 | */ |
| 199 | protected function findFrameworkType(string $type) |
| 200 | { |
| 201 | krsort($this->supportedTypes); |
| 202 | |
| 203 | foreach ($this->supportedTypes as $key => $val) { |
| 204 | if ($key === substr($type, 0, strlen($key))) { |
| 205 | return substr($type, 0, strlen($key)); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Get the second part of the regular expression to check for support of a |
| 214 | * package type |
| 215 | */ |
| 216 | protected function getLocationPattern(string $frameworkType): string |
| 217 | { |
| 218 | $pattern = null; |
| 219 | if (!empty($this->supportedTypes[$frameworkType])) { |
| 220 | $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; |
| 221 | /** @var BaseInstaller $framework */ |
| 222 | $framework = new $frameworkClass(new Package('dummy/pkg', '1.0.0.0', '1.0.0'), $this->composer, $this->getIO()); |
| 223 | $locations = array_keys($framework->getLocations($frameworkType)); |
| 224 | if ($locations) { |
| 225 | $pattern = '(' . implode('|', $locations) . ')'; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return $pattern ?: '(\w+)'; |
| 230 | } |
| 231 | |
| 232 | private function getIO(): IOInterface |
| 233 | { |
| 234 | return $this->io; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Look for installers set to be disabled in composer's extra config and |
| 239 | * remove them from the list of supported installers. |
| 240 | * |
| 241 | * Globals: |
| 242 | * - true, "all", and "*" - disable all installers. |
| 243 | * - false - enable all installers (useful with |
| 244 | * wikimedia/composer-merge-plugin or similar) |
| 245 | */ |
| 246 | protected function removeDisabledInstallers(): void |
| 247 | { |
| 248 | $extra = $this->composer->getPackage()->getExtra(); |
| 249 | |
| 250 | if (!isset($extra['installer-disable']) || $extra['installer-disable'] === false) { |
| 251 | // No installers are disabled |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | // Get installers to disable |
| 256 | $disable = $extra['installer-disable']; |
| 257 | |
| 258 | // Ensure $disabled is an array |
| 259 | if (!is_array($disable)) { |
| 260 | $disable = array($disable); |
| 261 | } |
| 262 | |
| 263 | // Check which installers should be disabled |
| 264 | $all = array(true, "all", "*"); |
| 265 | $intersect = array_intersect($all, $disable); |
| 266 | if (!empty($intersect)) { |
| 267 | // Disable all installers |
| 268 | $this->supportedTypes = array(); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | // Disable specified installers |
| 273 | foreach ($disable as $key => $installer) { |
| 274 | if (is_string($installer) && key_exists($installer, $this->supportedTypes)) { |
| 275 | unset($this->supportedTypes[$installer]); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 |