Chris@0: 'AimeosInstaller', Chris@0: 'asgard' => 'AsgardInstaller', Chris@0: 'attogram' => 'AttogramInstaller', Chris@0: 'agl' => 'AglInstaller', Chris@0: 'annotatecms' => 'AnnotateCmsInstaller', Chris@0: 'bitrix' => 'BitrixInstaller', Chris@0: 'bonefish' => 'BonefishInstaller', Chris@0: 'cakephp' => 'CakePHPInstaller', Chris@0: 'chef' => 'ChefInstaller', Chris@17: 'civicrm' => 'CiviCrmInstaller', Chris@0: 'ccframework' => 'ClanCatsFrameworkInstaller', Chris@0: 'cockpit' => 'CockpitInstaller', Chris@0: 'codeigniter' => 'CodeIgniterInstaller', Chris@0: 'concrete5' => 'Concrete5Installer', Chris@0: 'craft' => 'CraftInstaller', Chris@0: 'croogo' => 'CroogoInstaller', Chris@0: 'dokuwiki' => 'DokuWikiInstaller', Chris@0: 'dolibarr' => 'DolibarrInstaller', Chris@0: 'decibel' => 'DecibelInstaller', Chris@0: 'drupal' => 'DrupalInstaller', Chris@0: 'elgg' => 'ElggInstaller', Chris@0: 'eliasis' => 'EliasisInstaller', Chris@0: 'ee3' => 'ExpressionEngineInstaller', Chris@0: 'ee2' => 'ExpressionEngineInstaller', Chris@0: 'ezplatform' => 'EzPlatformInstaller', Chris@0: 'fuel' => 'FuelInstaller', Chris@0: 'fuelphp' => 'FuelphpInstaller', Chris@0: 'grav' => 'GravInstaller', Chris@0: 'hurad' => 'HuradInstaller', Chris@0: 'imagecms' => 'ImageCMSInstaller', Chris@0: 'itop' => 'ItopInstaller', Chris@0: 'joomla' => 'JoomlaInstaller', Chris@0: 'kanboard' => 'KanboardInstaller', Chris@0: 'kirby' => 'KirbyInstaller', Chris@0: 'kodicms' => 'KodiCMSInstaller', Chris@0: 'kohana' => 'KohanaInstaller', Chris@0: 'lms' => 'LanManagementSystemInstaller', Chris@0: 'laravel' => 'LaravelInstaller', Chris@0: 'lavalite' => 'LavaLiteInstaller', Chris@0: 'lithium' => 'LithiumInstaller', Chris@0: 'magento' => 'MagentoInstaller', Chris@12: 'majima' => 'MajimaInstaller', Chris@0: 'mako' => 'MakoInstaller', Chris@0: 'maya' => 'MayaInstaller', Chris@0: 'mautic' => 'MauticInstaller', Chris@0: 'mediawiki' => 'MediaWikiInstaller', Chris@0: 'microweber' => 'MicroweberInstaller', Chris@0: 'modulework' => 'MODULEWorkInstaller', Chris@12: 'modx' => 'ModxInstaller', Chris@0: 'modxevo' => 'MODXEvoInstaller', Chris@0: 'moodle' => 'MoodleInstaller', Chris@0: 'october' => 'OctoberInstaller', Chris@0: 'ontowiki' => 'OntoWikiInstaller', Chris@0: 'oxid' => 'OxidInstaller', Chris@0: 'osclass' => 'OsclassInstaller', Chris@12: 'pxcms' => 'PxcmsInstaller', Chris@0: 'phpbb' => 'PhpBBInstaller', Chris@0: 'pimcore' => 'PimcoreInstaller', Chris@0: 'piwik' => 'PiwikInstaller', Chris@0: 'plentymarkets'=> 'PlentymarketsInstaller', Chris@0: 'ppi' => 'PPIInstaller', Chris@0: 'puppet' => 'PuppetInstaller', Chris@0: 'radphp' => 'RadPHPInstaller', Chris@0: 'phifty' => 'PhiftyInstaller', Chris@0: 'porto' => 'PortoInstaller', Chris@0: 'redaxo' => 'RedaxoInstaller', Chris@0: 'reindex' => 'ReIndexInstaller', Chris@0: 'roundcube' => 'RoundcubeInstaller', Chris@0: 'shopware' => 'ShopwareInstaller', Chris@12: 'sitedirect' => 'SiteDirectInstaller', Chris@0: 'silverstripe' => 'SilverStripeInstaller', Chris@0: 'smf' => 'SMFInstaller', Chris@0: 'sydes' => 'SyDESInstaller', Chris@0: 'symfony1' => 'Symfony1Installer', Chris@0: 'thelia' => 'TheliaInstaller', Chris@0: 'tusk' => 'TuskInstaller', Chris@0: 'typo3-cms' => 'TYPO3CmsInstaller', Chris@0: 'typo3-flow' => 'TYPO3FlowInstaller', Chris@0: 'userfrosting' => 'UserFrostingInstaller', Chris@0: 'vanilla' => 'VanillaInstaller', Chris@0: 'whmcs' => 'WHMCSInstaller', Chris@0: 'wolfcms' => 'WolfCMSInstaller', Chris@0: 'wordpress' => 'WordPressInstaller', Chris@0: 'yawik' => 'YawikInstaller', Chris@0: 'zend' => 'ZendInstaller', Chris@0: 'zikula' => 'ZikulaInstaller', Chris@0: 'prestashop' => 'PrestashopInstaller' Chris@0: ); Chris@0: Chris@0: /** Chris@17: * Installer constructor. Chris@17: * Chris@17: * Disables installers specified in main composer extra installer-disable Chris@17: * list Chris@17: * Chris@17: * @param IOInterface $io Chris@17: * @param Composer $composer Chris@17: * @param string $type Chris@17: * @param Filesystem|null $filesystem Chris@17: * @param BinaryInstaller|null $binaryInstaller Chris@17: */ Chris@17: public function __construct( Chris@17: IOInterface $io, Chris@17: Composer $composer, Chris@17: $type = 'library', Chris@17: Filesystem $filesystem = null, Chris@17: BinaryInstaller $binaryInstaller = null Chris@17: ) { Chris@17: parent::__construct($io, $composer, $type, $filesystem, Chris@17: $binaryInstaller); Chris@17: $this->removeDisabledInstallers(); Chris@17: } Chris@17: Chris@17: /** Chris@0: * {@inheritDoc} Chris@0: */ Chris@0: public function getInstallPath(PackageInterface $package) Chris@0: { Chris@0: $type = $package->getType(); Chris@0: $frameworkType = $this->findFrameworkType($type); Chris@0: Chris@0: if ($frameworkType === false) { Chris@0: throw new \InvalidArgumentException( Chris@0: 'Sorry the package type of this package is not yet supported.' Chris@0: ); Chris@0: } Chris@0: Chris@0: $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; Chris@0: $installer = new $class($package, $this->composer, $this->getIO()); Chris@0: Chris@0: return $installer->getInstallPath($package, $frameworkType); Chris@0: } Chris@0: Chris@0: public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) Chris@0: { Chris@12: parent::uninstall($repo, $package); Chris@12: $installPath = $this->getPackageBasePath($package); Chris@12: $this->io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? 'deleted' : 'not deleted')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritDoc} Chris@0: */ Chris@0: public function supports($packageType) Chris@0: { Chris@0: $frameworkType = $this->findFrameworkType($packageType); Chris@0: Chris@0: if ($frameworkType === false) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: $locationPattern = $this->getLocationPattern($frameworkType); Chris@0: Chris@0: return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds a supported framework type if it exists and returns it Chris@0: * Chris@0: * @param string $type Chris@0: * @return string Chris@0: */ Chris@0: protected function findFrameworkType($type) Chris@0: { Chris@0: $frameworkType = false; Chris@0: Chris@0: krsort($this->supportedTypes); Chris@0: Chris@0: foreach ($this->supportedTypes as $key => $val) { Chris@0: if ($key === substr($type, 0, strlen($key))) { Chris@0: $frameworkType = substr($type, 0, strlen($key)); Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: return $frameworkType; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the second part of the regular expression to check for support of a Chris@0: * package type Chris@0: * Chris@0: * @param string $frameworkType Chris@0: * @return string Chris@0: */ Chris@0: protected function getLocationPattern($frameworkType) Chris@0: { Chris@0: $pattern = false; Chris@0: if (!empty($this->supportedTypes[$frameworkType])) { Chris@0: $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; Chris@0: /** @var BaseInstaller $framework */ Chris@0: $framework = new $frameworkClass(null, $this->composer, $this->getIO()); Chris@0: $locations = array_keys($framework->getLocations()); Chris@0: $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; Chris@0: } Chris@0: Chris@0: return $pattern ? : '(\w+)'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get I/O object Chris@0: * Chris@0: * @return IOInterface Chris@0: */ Chris@0: private function getIO() Chris@0: { Chris@0: return $this->io; Chris@0: } Chris@17: Chris@17: /** Chris@17: * Look for installers set to be disabled in composer's extra config and Chris@17: * remove them from the list of supported installers. Chris@17: * Chris@17: * Globals: Chris@17: * - true, "all", and "*" - disable all installers. Chris@17: * - false - enable all installers (useful with Chris@17: * wikimedia/composer-merge-plugin or similar) Chris@17: * Chris@17: * @return void Chris@17: */ Chris@17: protected function removeDisabledInstallers() Chris@17: { Chris@17: $extra = $this->composer->getPackage()->getExtra(); Chris@17: Chris@17: if (!isset($extra['installer-disable']) || $extra['installer-disable'] === false) { Chris@17: // No installers are disabled Chris@17: return; Chris@17: } Chris@17: Chris@17: // Get installers to disable Chris@17: $disable = $extra['installer-disable']; Chris@17: Chris@17: // Ensure $disabled is an array Chris@17: if (!is_array($disable)) { Chris@17: $disable = array($disable); Chris@17: } Chris@17: Chris@17: // Check which installers should be disabled Chris@17: $all = array(true, "all", "*"); Chris@17: $intersect = array_intersect($all, $disable); Chris@17: if (!empty($intersect)) { Chris@17: // Disable all installers Chris@17: $this->supportedTypes = array(); Chris@17: } else { Chris@17: // Disable specified installers Chris@17: foreach ($disable as $key => $installer) { Chris@17: if (is_string($installer) && key_exists($installer, $this->supportedTypes)) { Chris@17: unset($this->supportedTypes[$installer]); Chris@17: } Chris@17: } Chris@17: } Chris@17: } Chris@0: }