PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / composer / installers / src / Composer / Installers / BitrixInstaller.php

BitrixInstaller.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.2, at vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php

124 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 <[email protected]>
24 * @author Denis Kulichkin <[email protected]>
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