annotate vendor/composer/installers/src/Composer/Installers/Installer.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 129ea1e6d783
rev   line source
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@12 57 'majima' => 'MajimaInstaller',
Chris@0 58 'mako' => 'MakoInstaller',
Chris@0 59 'maya' => 'MayaInstaller',
Chris@0 60 'mautic' => 'MauticInstaller',
Chris@0 61 'mediawiki' => 'MediaWikiInstaller',
Chris@0 62 'microweber' => 'MicroweberInstaller',
Chris@0 63 'modulework' => 'MODULEWorkInstaller',
Chris@12 64 'modx' => 'ModxInstaller',
Chris@0 65 'modxevo' => 'MODXEvoInstaller',
Chris@0 66 'moodle' => 'MoodleInstaller',
Chris@0 67 'october' => 'OctoberInstaller',
Chris@0 68 'ontowiki' => 'OntoWikiInstaller',
Chris@0 69 'oxid' => 'OxidInstaller',
Chris@0 70 'osclass' => 'OsclassInstaller',
Chris@12 71 'pxcms' => 'PxcmsInstaller',
Chris@0 72 'phpbb' => 'PhpBBInstaller',
Chris@0 73 'pimcore' => 'PimcoreInstaller',
Chris@0 74 'piwik' => 'PiwikInstaller',
Chris@0 75 'plentymarkets'=> 'PlentymarketsInstaller',
Chris@0 76 'ppi' => 'PPIInstaller',
Chris@0 77 'puppet' => 'PuppetInstaller',
Chris@0 78 'radphp' => 'RadPHPInstaller',
Chris@0 79 'phifty' => 'PhiftyInstaller',
Chris@0 80 'porto' => 'PortoInstaller',
Chris@0 81 'redaxo' => 'RedaxoInstaller',
Chris@0 82 'reindex' => 'ReIndexInstaller',
Chris@0 83 'roundcube' => 'RoundcubeInstaller',
Chris@0 84 'shopware' => 'ShopwareInstaller',
Chris@12 85 'sitedirect' => 'SiteDirectInstaller',
Chris@0 86 'silverstripe' => 'SilverStripeInstaller',
Chris@0 87 'smf' => 'SMFInstaller',
Chris@0 88 'sydes' => 'SyDESInstaller',
Chris@0 89 'symfony1' => 'Symfony1Installer',
Chris@0 90 'thelia' => 'TheliaInstaller',
Chris@0 91 'tusk' => 'TuskInstaller',
Chris@0 92 'typo3-cms' => 'TYPO3CmsInstaller',
Chris@0 93 'typo3-flow' => 'TYPO3FlowInstaller',
Chris@0 94 'userfrosting' => 'UserFrostingInstaller',
Chris@0 95 'vanilla' => 'VanillaInstaller',
Chris@0 96 'whmcs' => 'WHMCSInstaller',
Chris@0 97 'wolfcms' => 'WolfCMSInstaller',
Chris@0 98 'wordpress' => 'WordPressInstaller',
Chris@0 99 'yawik' => 'YawikInstaller',
Chris@0 100 'zend' => 'ZendInstaller',
Chris@0 101 'zikula' => 'ZikulaInstaller',
Chris@0 102 'prestashop' => 'PrestashopInstaller'
Chris@0 103 );
Chris@0 104
Chris@0 105 /**
Chris@0 106 * {@inheritDoc}
Chris@0 107 */
Chris@0 108 public function getInstallPath(PackageInterface $package)
Chris@0 109 {
Chris@0 110 $type = $package->getType();
Chris@0 111 $frameworkType = $this->findFrameworkType($type);
Chris@0 112
Chris@0 113 if ($frameworkType === false) {
Chris@0 114 throw new \InvalidArgumentException(
Chris@0 115 'Sorry the package type of this package is not yet supported.'
Chris@0 116 );
Chris@0 117 }
Chris@0 118
Chris@0 119 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
Chris@0 120 $installer = new $class($package, $this->composer, $this->getIO());
Chris@0 121
Chris@0 122 return $installer->getInstallPath($package, $frameworkType);
Chris@0 123 }
Chris@0 124
Chris@0 125 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
Chris@0 126 {
Chris@12 127 parent::uninstall($repo, $package);
Chris@12 128 $installPath = $this->getPackageBasePath($package);
Chris@12 129 $this->io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
Chris@0 130 }
Chris@0 131
Chris@0 132 /**
Chris@0 133 * {@inheritDoc}
Chris@0 134 */
Chris@0 135 public function supports($packageType)
Chris@0 136 {
Chris@0 137 $frameworkType = $this->findFrameworkType($packageType);
Chris@0 138
Chris@0 139 if ($frameworkType === false) {
Chris@0 140 return false;
Chris@0 141 }
Chris@0 142
Chris@0 143 $locationPattern = $this->getLocationPattern($frameworkType);
Chris@0 144
Chris@0 145 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
Chris@0 146 }
Chris@0 147
Chris@0 148 /**
Chris@0 149 * Finds a supported framework type if it exists and returns it
Chris@0 150 *
Chris@0 151 * @param string $type
Chris@0 152 * @return string
Chris@0 153 */
Chris@0 154 protected function findFrameworkType($type)
Chris@0 155 {
Chris@0 156 $frameworkType = false;
Chris@0 157
Chris@0 158 krsort($this->supportedTypes);
Chris@0 159
Chris@0 160 foreach ($this->supportedTypes as $key => $val) {
Chris@0 161 if ($key === substr($type, 0, strlen($key))) {
Chris@0 162 $frameworkType = substr($type, 0, strlen($key));
Chris@0 163 break;
Chris@0 164 }
Chris@0 165 }
Chris@0 166
Chris@0 167 return $frameworkType;
Chris@0 168 }
Chris@0 169
Chris@0 170 /**
Chris@0 171 * Get the second part of the regular expression to check for support of a
Chris@0 172 * package type
Chris@0 173 *
Chris@0 174 * @param string $frameworkType
Chris@0 175 * @return string
Chris@0 176 */
Chris@0 177 protected function getLocationPattern($frameworkType)
Chris@0 178 {
Chris@0 179 $pattern = false;
Chris@0 180 if (!empty($this->supportedTypes[$frameworkType])) {
Chris@0 181 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
Chris@0 182 /** @var BaseInstaller $framework */
Chris@0 183 $framework = new $frameworkClass(null, $this->composer, $this->getIO());
Chris@0 184 $locations = array_keys($framework->getLocations());
Chris@0 185 $pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
Chris@0 186 }
Chris@0 187
Chris@0 188 return $pattern ? : '(\w+)';
Chris@0 189 }
Chris@0 190
Chris@0 191 /**
Chris@0 192 * Get I/O object
Chris@0 193 *
Chris@0 194 * @return IOInterface
Chris@0 195 */
Chris@0 196 private function getIO()
Chris@0 197 {
Chris@0 198 return $this->io;
Chris@0 199 }
Chris@0 200 }