AglInstaller.php
4 years ago
AimeosInstaller.php
4 years ago
AnnotateCmsInstaller.php
4 years ago
AsgardInstaller.php
4 years ago
AttogramInstaller.php
4 years ago
BaseInstaller.php
4 years ago
BitrixInstaller.php
4 years ago
BonefishInstaller.php
4 years ago
CakePHPInstaller.php
4 years ago
ChefInstaller.php
4 years ago
CiviCrmInstaller.php
4 years ago
ClanCatsFrameworkInstaller.php
4 years ago
CockpitInstaller.php
4 years ago
CodeIgniterInstaller.php
4 years ago
Concrete5Installer.php
4 years ago
CraftInstaller.php
4 years ago
CroogoInstaller.php
4 years ago
DecibelInstaller.php
4 years ago
DframeInstaller.php
4 years ago
DokuWikiInstaller.php
4 years ago
DolibarrInstaller.php
4 years ago
DrupalInstaller.php
4 years ago
ElggInstaller.php
4 years ago
EliasisInstaller.php
4 years ago
ExpressionEngineInstaller.php
4 years ago
EzPlatformInstaller.php
4 years ago
FuelInstaller.php
4 years ago
FuelphpInstaller.php
4 years ago
GravInstaller.php
4 years ago
HuradInstaller.php
4 years ago
ImageCMSInstaller.php
4 years ago
Installer.php
4 years ago
ItopInstaller.php
4 years ago
JoomlaInstaller.php
4 years ago
KanboardInstaller.php
4 years ago
KirbyInstaller.php
4 years ago
KnownInstaller.php
4 years ago
KodiCMSInstaller.php
4 years ago
KohanaInstaller.php
4 years ago
LanManagementSystemInstaller.php
4 years ago
LaravelInstaller.php
4 years ago
LavaLiteInstaller.php
4 years ago
LithiumInstaller.php
4 years ago
MODULEWorkInstaller.php
4 years ago
MODXEvoInstaller.php
4 years ago
MagentoInstaller.php
4 years ago
MajimaInstaller.php
4 years ago
MakoInstaller.php
4 years ago
MantisBTInstaller.php
4 years ago
MauticInstaller.php
4 years ago
MayaInstaller.php
4 years ago
MediaWikiInstaller.php
4 years ago
MiaoxingInstaller.php
4 years ago
MicroweberInstaller.php
4 years ago
ModxInstaller.php
4 years ago
MoodleInstaller.php
4 years ago
OctoberInstaller.php
4 years ago
OntoWikiInstaller.php
4 years ago
OsclassInstaller.php
4 years ago
OxidInstaller.php
4 years ago
PPIInstaller.php
4 years ago
PantheonInstaller.php
4 years ago
PhiftyInstaller.php
4 years ago
PhpBBInstaller.php
4 years ago
PimcoreInstaller.php
4 years ago
PiwikInstaller.php
4 years ago
PlentymarketsInstaller.php
4 years ago
Plugin.php
4 years ago
PortoInstaller.php
4 years ago
PrestashopInstaller.php
4 years ago
ProcessWireInstaller.php
4 years ago
PuppetInstaller.php
4 years ago
PxcmsInstaller.php
4 years ago
RadPHPInstaller.php
4 years ago
ReIndexInstaller.php
4 years ago
Redaxo5Installer.php
4 years ago
RedaxoInstaller.php
4 years ago
RoundcubeInstaller.php
4 years ago
SMFInstaller.php
4 years ago
ShopwareInstaller.php
4 years ago
SilverStripeInstaller.php
4 years ago
SiteDirectInstaller.php
4 years ago
StarbugInstaller.php
4 years ago
SyDESInstaller.php
4 years ago
SyliusInstaller.php
4 years ago
Symfony1Installer.php
4 years ago
TYPO3CmsInstaller.php
4 years ago
TYPO3FlowInstaller.php
4 years ago
TaoInstaller.php
4 years ago
TastyIgniterInstaller.php
4 years ago
TheliaInstaller.php
4 years ago
TuskInstaller.php
4 years ago
UserFrostingInstaller.php
4 years ago
VanillaInstaller.php
4 years ago
VgmcpInstaller.php
4 years ago
WHMCSInstaller.php
4 years ago
WinterInstaller.php
4 years ago
WolfCMSInstaller.php
4 years ago
WordPressInstaller.php
4 years ago
YawikInstaller.php
4 years ago
ZendInstaller.php
4 years ago
ZikulaInstaller.php
4 years ago
BaseInstaller.php
138 lines
| 1 | <?php |
| 2 | namespace Composer\Installers; |
| 3 | |
| 4 | use Composer\IO\IOInterface; |
| 5 | use Composer\Composer; |
| 6 | use Composer\Package\PackageInterface; |
| 7 | |
| 8 | abstract class BaseInstaller |
| 9 | { |
| 10 | protected $locations = array(); |
| 11 | protected $composer; |
| 12 | protected $package; |
| 13 | protected $io; |
| 14 | |
| 15 | /** |
| 16 | * Initializes base installer. |
| 17 | * |
| 18 | * @param PackageInterface $package |
| 19 | * @param Composer $composer |
| 20 | * @param IOInterface $io |
| 21 | */ |
| 22 | public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null) |
| 23 | { |
| 24 | $this->composer = $composer; |
| 25 | $this->package = $package; |
| 26 | $this->io = $io; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Return the install path based on package type. |
| 31 | * |
| 32 | * @param PackageInterface $package |
| 33 | * @param string $frameworkType |
| 34 | * @return string |
| 35 | */ |
| 36 | public function getInstallPath(PackageInterface $package, $frameworkType = '') |
| 37 | { |
| 38 | $type = $this->package->getType(); |
| 39 | |
| 40 | $prettyName = $this->package->getPrettyName(); |
| 41 | if (strpos($prettyName, '/') !== false) { |
| 42 | list($vendor, $name) = explode('/', $prettyName); |
| 43 | } else { |
| 44 | $vendor = ''; |
| 45 | $name = $prettyName; |
| 46 | } |
| 47 | |
| 48 | $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type')); |
| 49 | |
| 50 | $extra = $package->getExtra(); |
| 51 | if (!empty($extra['installer-name'])) { |
| 52 | $availableVars['name'] = $extra['installer-name']; |
| 53 | } |
| 54 | |
| 55 | if ($this->composer->getPackage()) { |
| 56 | $extra = $this->composer->getPackage()->getExtra(); |
| 57 | if (!empty($extra['installer-paths'])) { |
| 58 | $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor); |
| 59 | if ($customPath !== false) { |
| 60 | return $this->templatePath($customPath, $availableVars); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | $packageType = substr($type, strlen($frameworkType) + 1); |
| 66 | $locations = $this->getLocations(); |
| 67 | if (!isset($locations[$packageType])) { |
| 68 | throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type)); |
| 69 | } |
| 70 | |
| 71 | return $this->templatePath($locations[$packageType], $availableVars); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * For an installer to override to modify the vars per installer. |
| 76 | * |
| 77 | * @param array<string, string> $vars This will normally receive array{name: string, vendor: string, type: string} |
| 78 | * @return array<string, string> |
| 79 | */ |
| 80 | public function inflectPackageVars($vars) |
| 81 | { |
| 82 | return $vars; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Gets the installer's locations |
| 87 | * |
| 88 | * @return array<string, string> map of package types => install path |
| 89 | */ |
| 90 | public function getLocations() |
| 91 | { |
| 92 | return $this->locations; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Replace vars in a path |
| 97 | * |
| 98 | * @param string $path |
| 99 | * @param array<string, string> $vars |
| 100 | * @return string |
| 101 | */ |
| 102 | protected function templatePath($path, array $vars = array()) |
| 103 | { |
| 104 | if (strpos($path, '{') !== false) { |
| 105 | extract($vars); |
| 106 | preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches); |
| 107 | if (!empty($matches[1])) { |
| 108 | foreach ($matches[1] as $var) { |
| 109 | $path = str_replace('{$' . $var . '}', $$var, $path); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return $path; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Search through a passed paths array for a custom install path. |
| 119 | * |
| 120 | * @param array $paths |
| 121 | * @param string $name |
| 122 | * @param string $type |
| 123 | * @param string $vendor = NULL |
| 124 | * @return string|false |
| 125 | */ |
| 126 | protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = NULL) |
| 127 | { |
| 128 | foreach ($paths as $path => $names) { |
| 129 | $names = (array) $names; |
| 130 | if (in_array($name, $names) || in_array('type:' . $type, $names) || in_array('vendor:' . $vendor, $names)) { |
| 131 | return $path; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return false; |
| 136 | } |
| 137 | } |
| 138 |