/vendor/composer/installers/src/Composer/Installers/Installer.php

  1. <?php 
  2. namespace Composer\Installers; 
  3.  
  4. use Composer\Installer\LibraryInstaller; 
  5. use Composer\Package\PackageInterface; 
  6. use Composer\Repository\InstalledRepositoryInterface; 
  7.  
  8. class Installer extends LibraryInstaller 
  9. /** 
  10. * Package types to installer class map 
  11. * 
  12. * @var array 
  13. */ 
  14. private $supportedTypes = array( 
  15. 'aimeos' => 'AimeosInstaller',  
  16. 'asgard' => 'AsgardInstaller',  
  17. 'agl' => 'AglInstaller',  
  18. 'annotatecms' => 'AnnotateCmsInstaller',  
  19. 'bitrix' => 'BitrixInstaller',  
  20. 'cakephp' => 'CakePHPInstaller',  
  21. 'chef' => 'ChefInstaller',  
  22. 'ccframework' => 'ClanCatsFrameworkInstaller',  
  23. 'codeigniter' => 'CodeIgniterInstaller',  
  24. 'concrete5' => 'Concrete5Installer',  
  25. 'craft' => 'CraftInstaller',  
  26. 'croogo' => 'CroogoInstaller',  
  27. 'dokuwiki' => 'DokuWikiInstaller',  
  28. 'dolibarr' => 'DolibarrInstaller',  
  29. 'drupal' => 'DrupalInstaller',  
  30. 'elgg' => 'ElggInstaller',  
  31. 'fuel' => 'FuelInstaller',  
  32. 'fuelphp' => 'FuelphpInstaller',  
  33. 'grav' => 'GravInstaller',  
  34. 'hurad' => 'HuradInstaller',  
  35. 'joomla' => 'JoomlaInstaller',  
  36. 'kirby' => 'KirbyInstaller',  
  37. 'kohana' => 'KohanaInstaller',  
  38. 'laravel' => 'LaravelInstaller',  
  39. 'lithium' => 'LithiumInstaller',  
  40. 'magento' => 'MagentoInstaller',  
  41. 'mako' => 'MakoInstaller',  
  42. 'mediawiki' => 'MediaWikiInstaller',  
  43. 'microweber' => 'MicroweberInstaller',  
  44. 'modulework' => 'MODULEWorkInstaller',  
  45. 'modxevo' => 'MODXEvoInstaller',  
  46. 'moodle' => 'MoodleInstaller',  
  47. 'october' => 'OctoberInstaller',  
  48. 'oxid' => 'OxidInstaller',  
  49. 'phpbb' => 'PhpBBInstaller',  
  50. 'pimcore' => 'PimcoreInstaller',  
  51. 'piwik' => 'PiwikInstaller',  
  52. 'ppi' => 'PPIInstaller',  
  53. 'puppet' => 'PuppetInstaller',  
  54. 'redaxo' => 'RedaxoInstaller',  
  55. 'roundcube' => 'RoundcubeInstaller',  
  56. 'shopware' => 'ShopwareInstaller',  
  57. 'silverstripe' => 'SilverStripeInstaller',  
  58. 'smf' => 'SMFInstaller',  
  59. 'symfony1' => 'Symfony1Installer',  
  60. 'thelia' => 'TheliaInstaller',  
  61. 'tusk' => 'TuskInstaller',  
  62. 'typo3-cms' => 'TYPO3CmsInstaller',  
  63. 'typo3-flow' => 'TYPO3FlowInstaller',  
  64. 'whmcs' => 'WHMCSInstaller',  
  65. 'wolfcms' => 'WolfCMSInstaller',  
  66. 'wordpress' => 'WordPressInstaller',  
  67. 'zend' => 'ZendInstaller',  
  68. 'zikula' => 'ZikulaInstaller',  
  69. 'prestashop' => 'PrestashopInstaller',  
  70. ); 
  71.  
  72. /** 
  73. * {@inheritDoc} 
  74. */ 
  75. public function getInstallPath(PackageInterface $package) 
  76. $type = $package->getType(); 
  77. $frameworkType = $this->findFrameworkType($type); 
  78.  
  79. if ($frameworkType === false) { 
  80. throw new \InvalidArgumentException( 
  81. 'Sorry the package type of this package is not yet supported.' 
  82. ); 
  83.  
  84. $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; 
  85. $installer = new $class($package, $this->composer); 
  86.  
  87. return $installer->getInstallPath($package, $frameworkType); 
  88.  
  89. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) 
  90. if (!$repo->hasPackage($package)) { 
  91. throw new \InvalidArgumentException('Package is not installed: '.$package); 
  92.  
  93. $repo->removePackage($package); 
  94.  
  95. $installPath = $this->getInstallPath($package); 
  96. $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); 
  97.  
  98. /** 
  99. * {@inheritDoc} 
  100. */ 
  101. public function supports($packageType) 
  102. $frameworkType = $this->findFrameworkType($packageType); 
  103.  
  104. if ($frameworkType === false) { 
  105. return false; 
  106.  
  107. $locationPattern = $this->getLocationPattern($frameworkType); 
  108.  
  109. return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1; 
  110.  
  111. /** 
  112. * Finds a supported framework type if it exists and returns it 
  113. * 
  114. * @param string $type 
  115. * @return string 
  116. */ 
  117. protected function findFrameworkType($type) 
  118. $frameworkType = false; 
  119.  
  120. krsort($this->supportedTypes); 
  121.  
  122. foreach ($this->supportedTypes as $key => $val) { 
  123. if ($key === substr($type, 0, strlen($key))) { 
  124. $frameworkType = substr($type, 0, strlen($key)); 
  125. break; 
  126.  
  127. return $frameworkType; 
  128.  
  129. /** 
  130. * Get the second part of the regular expression to check for support of a 
  131. * package type 
  132. * 
  133. * @param string $frameworkType 
  134. * @return string 
  135. */ 
  136. protected function getLocationPattern($frameworkType) 
  137. $pattern = false; 
  138. if (!empty($this->supportedTypes[$frameworkType])) { 
  139. $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; 
  140. /** @var BaseInstaller $framework */ 
  141. $framework = new $frameworkClass(null, $this->composer); 
  142. $locations = array_keys($framework->getLocations()); 
  143. $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; 
  144.  
  145. return $pattern ? : '(\w+)'; 
.