AglInstaller.php
6 months ago
AkauntingInstaller.php
6 months ago
AnnotateCmsInstaller.php
6 months ago
AsgardInstaller.php
6 months ago
AttogramInstaller.php
6 months ago
BaseInstaller.php
6 months ago
BitrixInstaller.php
6 months ago
BonefishInstaller.php
6 months ago
CakePHPInstaller.php
6 months ago
ChefInstaller.php
6 months ago
CiviCrmInstaller.php
6 months ago
ClanCatsFrameworkInstaller.php
6 months ago
CockpitInstaller.php
6 months ago
CodeIgniterInstaller.php
6 months ago
Concrete5Installer.php
6 months ago
CroogoInstaller.php
6 months ago
DecibelInstaller.php
6 months ago
DframeInstaller.php
6 months ago
DokuWikiInstaller.php
6 months ago
DolibarrInstaller.php
6 months ago
DrupalInstaller.php
6 months ago
ElggInstaller.php
6 months ago
EliasisInstaller.php
6 months ago
ExpressionEngineInstaller.php
6 months ago
EzPlatformInstaller.php
6 months ago
FuelInstaller.php
6 months ago
FuelphpInstaller.php
6 months ago
GravInstaller.php
6 months ago
HuradInstaller.php
6 months ago
ImageCMSInstaller.php
6 months ago
Installer.php
6 months ago
ItopInstaller.php
6 months ago
KanboardInstaller.php
6 months ago
KnownInstaller.php
6 months ago
KodiCMSInstaller.php
6 months ago
KohanaInstaller.php
6 months ago
LanManagementSystemInstaller.php
6 months ago
LaravelInstaller.php
6 months ago
LavaLiteInstaller.php
6 months ago
LithiumInstaller.php
6 months ago
MODULEWorkInstaller.php
6 months ago
MODXEvoInstaller.php
6 months ago
MagentoInstaller.php
6 months ago
MajimaInstaller.php
6 months ago
MakoInstaller.php
6 months ago
MantisBTInstaller.php
6 months ago
MauticInstaller.php
6 months ago
MayaInstaller.php
6 months ago
MediaWikiInstaller.php
6 months ago
MiaoxingInstaller.php
6 months ago
MicroweberInstaller.php
6 months ago
ModxInstaller.php
6 months ago
MoodleInstaller.php
6 months ago
OctoberInstaller.php
6 months ago
OntoWikiInstaller.php
6 months ago
OsclassInstaller.php
6 months ago
OxidInstaller.php
6 months ago
PPIInstaller.php
6 months ago
PantheonInstaller.php
6 months ago
PhiftyInstaller.php
6 months ago
PhpBBInstaller.php
6 months ago
PiwikInstaller.php
6 months ago
PlentymarketsInstaller.php
6 months ago
Plugin.php
6 months ago
PortoInstaller.php
6 months ago
PrestashopInstaller.php
6 months ago
ProcessWireInstaller.php
6 months ago
PuppetInstaller.php
6 months ago
PxcmsInstaller.php
6 months ago
RadPHPInstaller.php
6 months ago
ReIndexInstaller.php
6 months ago
Redaxo5Installer.php
6 months ago
RedaxoInstaller.php
6 months ago
RoundcubeInstaller.php
6 months ago
SMFInstaller.php
6 months ago
ShopwareInstaller.php
6 months ago
SilverStripeInstaller.php
6 months ago
SiteDirectInstaller.php
6 months ago
StarbugInstaller.php
6 months ago
SyDESInstaller.php
6 months ago
SyliusInstaller.php
6 months ago
TaoInstaller.php
6 months ago
TastyIgniterInstaller.php
6 months ago
TheliaInstaller.php
6 months ago
TuskInstaller.php
6 months ago
UserFrostingInstaller.php
6 months ago
VanillaInstaller.php
6 months ago
VgmcpInstaller.php
6 months ago
WHMCSInstaller.php
6 months ago
WinterInstaller.php
6 months ago
WolfCMSInstaller.php
6 months ago
WordPressInstaller.php
6 months ago
YawikInstaller.php
6 months ago
ZendInstaller.php
6 months ago
ZikulaInstaller.php
6 months ago
BitrixInstaller.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Composer\Installers; |
| 4 | |
| 5 | use Composer\Util\Filesystem; |
| 6 | |
| 7 | /** |
| 8 | * Installer for Bitrix Framework. Supported types of extensions: |
| 9 | * - `bitrix-d7-module` — copy the module to directory `bitrix/modules/<vendor>.<name>`. |
| 10 | * - `bitrix-d7-component` — copy the component to directory `bitrix/components/<vendor>/<name>`. |
| 11 | * - `bitrix-d7-template` — copy the template to directory `bitrix/templates/<vendor>_<name>`. |
| 12 | * |
| 13 | * You can set custom path to directory with Bitrix kernel in `composer.json`: |
| 14 | * |
| 15 | * ```json |
| 16 | * { |
| 17 | * "extra": { |
| 18 | * "bitrix-dir": "s1/bitrix" |
| 19 | * } |
| 20 | * } |
| 21 | * ``` |
| 22 | * |
| 23 | * @author Nik Samokhvalov <nik@samokhvalov.info> |
| 24 | * @author Denis Kulichkin <onexhovia@gmail.com> |
| 25 | */ |
| 26 | class BitrixInstaller extends BaseInstaller |
| 27 | { |
| 28 | /** @var array<string, string> */ |
| 29 | protected $locations = array( |
| 30 | 'module' => '{$bitrix_dir}/modules/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
| 31 | 'component' => '{$bitrix_dir}/components/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
| 32 | 'theme' => '{$bitrix_dir}/templates/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
| 33 | 'd7-module' => '{$bitrix_dir}/modules/{$vendor}.{$name}/', |
| 34 | 'd7-component' => '{$bitrix_dir}/components/{$vendor}/{$name}/', |
| 35 | 'd7-template' => '{$bitrix_dir}/templates/{$vendor}_{$name}/', |
| 36 | ); |
| 37 | |
| 38 | /** |
| 39 | * @var string[] Storage for informations about duplicates at all the time of installation packages. |
| 40 | */ |
| 41 | private static $checkedDuplicates = array(); |
| 42 | |
| 43 | public function inflectPackageVars(array $vars): array |
| 44 | { |
| 45 | /** @phpstan-ignore-next-line */ |
| 46 | if ($this->composer->getPackage()) { |
| 47 | $extra = $this->composer->getPackage()->getExtra(); |
| 48 | |
| 49 | if (isset($extra['bitrix-dir'])) { |
| 50 | $vars['bitrix_dir'] = $extra['bitrix-dir']; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (!isset($vars['bitrix_dir'])) { |
| 55 | $vars['bitrix_dir'] = 'bitrix'; |
| 56 | } |
| 57 | |
| 58 | return parent::inflectPackageVars($vars); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * {@inheritdoc} |
| 63 | */ |
| 64 | protected function templatePath(string $path, array $vars = array()): string |
| 65 | { |
| 66 | $templatePath = parent::templatePath($path, $vars); |
| 67 | $this->checkDuplicates($templatePath, $vars); |
| 68 | |
| 69 | return $templatePath; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Duplicates search packages. |
| 74 | * |
| 75 | * @param array<string, string> $vars |
| 76 | */ |
| 77 | protected function checkDuplicates(string $path, array $vars = array()): void |
| 78 | { |
| 79 | $packageType = substr($vars['type'], strlen('bitrix') + 1); |
| 80 | $localDir = explode('/', $vars['bitrix_dir']); |
| 81 | array_pop($localDir); |
| 82 | $localDir[] = 'local'; |
| 83 | $localDir = implode('/', $localDir); |
| 84 | |
| 85 | $oldPath = str_replace( |
| 86 | array('{$bitrix_dir}', '{$name}'), |
| 87 | array($localDir, $vars['name']), |
| 88 | $this->locations[$packageType] |
| 89 | ); |
| 90 | |
| 91 | if (in_array($oldPath, static::$checkedDuplicates)) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | if ($oldPath !== $path && file_exists($oldPath) && $this->io->isInteractive()) { |
| 96 | $this->io->writeError(' <error>Duplication of packages:</error>'); |
| 97 | $this->io->writeError(' <info>Package ' . $oldPath . ' will be called instead package ' . $path . '</info>'); |
| 98 | |
| 99 | while (true) { |
| 100 | switch ($this->io->ask(' <info>Delete ' . $oldPath . ' [y,n,?]?</info> ', '?')) { |
| 101 | case 'y': |
| 102 | $fs = new Filesystem(); |
| 103 | $fs->removeDirectory($oldPath); |
| 104 | break 2; |
| 105 | |
| 106 | case 'n': |
| 107 | break 2; |
| 108 | |
| 109 | case '?': |
| 110 | default: |
| 111 | $this->io->writeError(array( |
| 112 | ' y - delete package ' . $oldPath . ' and to continue with the installation', |
| 113 | ' n - don\'t delete and to continue with the installation', |
| 114 | )); |
| 115 | $this->io->writeError(' ? - print help'); |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static::$checkedDuplicates[] = $oldPath; |
| 122 | } |
| 123 | } |
| 124 |