annotate vendor/composer/installers/src/Composer/Installers/Installer.php @ 19:fa3358dc1485 tip

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