PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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 / Installer.php

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

289 lines 10.0 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\Composer;
6 use Composer\Installer\BinaryInstaller;
7 use Composer\Installer\LibraryInstaller;
8 use Composer\IO\IOInterface;
9 use Composer\Package\Package;
10 use Composer\Package\PackageInterface;
11 use Composer\Repository\InstalledRepositoryInterface;
12 use Composer\Util\Filesystem;
13 use React\Promise\PromiseInterface;
14
15 class Installer extends LibraryInstaller
16 {
17 /**
18 * Package types to installer class map
19 *
20 * @var array<string, string>
21 */
22 private $supportedTypes = array(
23 'akaunting' => 'AkauntingInstaller',
24 'asgard' => 'AsgardInstaller',
25 'attogram' => 'AttogramInstaller',
26 'agl' => 'AglInstaller',
27 'annotatecms' => 'AnnotateCmsInstaller',
28 'bitrix' => 'BitrixInstaller',
29 'botble' => 'BotbleInstaller',
30 'bonefish' => 'BonefishInstaller',
31 'cakephp' => 'CakePHPInstaller',
32 'chef' => 'ChefInstaller',
33 'civicrm' => 'CiviCrmInstaller',
34 'ccframework' => 'ClanCatsFrameworkInstaller',
35 'cockpit' => 'CockpitInstaller',
36 'codeigniter' => 'CodeIgniterInstaller',
37 'concrete5' => 'Concrete5Installer',
38 'concretecms' => 'ConcreteCMSInstaller',
39 'croogo' => 'CroogoInstaller',
40 'dframe' => 'DframeInstaller',
41 'dokuwiki' => 'DokuWikiInstaller',
42 'dolibarr' => 'DolibarrInstaller',
43 'decibel' => 'DecibelInstaller',
44 'drupal' => 'DrupalInstaller',
45 'elgg' => 'ElggInstaller',
46 'eliasis' => 'EliasisInstaller',
47 'ee3' => 'ExpressionEngineInstaller',
48 'ee2' => 'ExpressionEngineInstaller',
49 'ezplatform' => 'EzPlatformInstaller',
50 'fork' => 'ForkCMSInstaller',
51 'fuel' => 'FuelInstaller',
52 'fuelphp' => 'FuelphpInstaller',
53 'grav' => 'GravInstaller',
54 'hurad' => 'HuradInstaller',
55 'tastyigniter' => 'TastyIgniterInstaller',
56 'imagecms' => 'ImageCMSInstaller',
57 'itop' => 'ItopInstaller',
58 'kanboard' => 'KanboardInstaller',
59 'known' => 'KnownInstaller',
60 'kodicms' => 'KodiCMSInstaller',
61 'kohana' => 'KohanaInstaller',
62 'lms' => 'LanManagementSystemInstaller',
63 'laravel' => 'LaravelInstaller',
64 'lavalite' => 'LavaLiteInstaller',
65 'lithium' => 'LithiumInstaller',
66 'magento' => 'MagentoInstaller',
67 'majima' => 'MajimaInstaller',
68 'mantisbt' => 'MantisBTInstaller',
69 'mako' => 'MakoInstaller',
70 'matomo' => 'MatomoInstaller',
71 'maya' => 'MayaInstaller',
72 'mautic' => 'MauticInstaller',
73 'mediawiki' => 'MediaWikiInstaller',
74 'miaoxing' => 'MiaoxingInstaller',
75 'microweber' => 'MicroweberInstaller',
76 'modulework' => 'MODULEWorkInstaller',
77 'modx' => 'ModxInstaller',
78 'modxevo' => 'MODXEvoInstaller',
79 'moodle' => 'MoodleInstaller',
80 'october' => 'OctoberInstaller',
81 'ontowiki' => 'OntoWikiInstaller',
82 'oxid' => 'OxidInstaller',
83 'osclass' => 'OsclassInstaller',
84 'pxcms' => 'PxcmsInstaller',
85 'phpbb' => 'PhpBBInstaller',
86 'piwik' => 'PiwikInstaller',
87 'plentymarkets'=> 'PlentymarketsInstaller',
88 'ppi' => 'PPIInstaller',
89 'puppet' => 'PuppetInstaller',
90 'radphp' => 'RadPHPInstaller',
91 'phifty' => 'PhiftyInstaller',
92 'porto' => 'PortoInstaller',
93 'processwire' => 'ProcessWireInstaller',
94 'quicksilver' => 'PantheonInstaller',
95 'redaxo' => 'RedaxoInstaller',
96 'redaxo5' => 'Redaxo5Installer',
97 'reindex' => 'ReIndexInstaller',
98 'roundcube' => 'RoundcubeInstaller',
99 'shopware' => 'ShopwareInstaller',
100 'sitedirect' => 'SiteDirectInstaller',
101 'silverstripe' => 'SilverStripeInstaller',
102 'smf' => 'SMFInstaller',
103 'starbug' => 'StarbugInstaller',
104 'sydes' => 'SyDESInstaller',
105 'sylius' => 'SyliusInstaller',
106 'tao' => 'TaoInstaller',
107 'thelia' => 'TheliaInstaller',
108 'tusk' => 'TuskInstaller',
109 'userfrosting' => 'UserFrostingInstaller',
110 'vanilla' => 'VanillaInstaller',
111 'whmcs' => 'WHMCSInstaller',
112 'winter' => 'WinterInstaller',
113 'wolfcms' => 'WolfCMSInstaller',
114 'wordpress' => 'WordPressInstaller',
115 'yawik' => 'YawikInstaller',
116 'zend' => 'ZendInstaller',
117 'zikula' => 'ZikulaInstaller',
118 'prestashop' => 'PrestashopInstaller'
119 );
120
121 /**
122 * Disables installers specified in main composer extra installer-disable
123 * list
124 */
125 public function __construct(
126 IOInterface $io,
127 Composer $composer,
128 string $type = 'library',
129 ?Filesystem $filesystem = null,
130 ?BinaryInstaller $binaryInstaller = null
131 ) {
132 parent::__construct($io, $composer, $type, $filesystem, $binaryInstaller);
133 $this->removeDisabledInstallers();
134 }
135
136 /**
137 * {@inheritDoc}
138 */
139 public function getInstallPath(PackageInterface $package)
140 {
141 $type = $package->getType();
142 $frameworkType = $this->findFrameworkType($type);
143
144 if ($frameworkType === false) {
145 throw new \InvalidArgumentException(
146 'Sorry the package type of this package is not yet supported.'
147 );
148 }
149
150 $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
151 /**
152 * @var BaseInstaller
153 */
154 $installer = new $class($package, $this->composer, $this->getIO());
155
156 $path = $installer->getInstallPath($package, $frameworkType);
157 if (!$this->filesystem->isAbsolutePath($path)) {
158 $path = getcwd() . '/' . $path;
159 }
160
161 return $path;
162 }
163
164 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
165 {
166 $installPath = $this->getPackageBasePath($package);
167 $io = $this->io;
168 $outputStatus = function () use ($io, $installPath) {
169 $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
170 };
171
172 $promise = parent::uninstall($repo, $package);
173
174 // Composer v2 might return a promise here
175 if ($promise instanceof PromiseInterface) {
176 return $promise->then($outputStatus);
177 }
178
179 // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)
180 $outputStatus();
181
182 return null;
183 }
184
185 /**
186 * {@inheritDoc}
187 *
188 * @param string $packageType
189 */
190 public function supports($packageType)
191 {
192 $frameworkType = $this->findFrameworkType($packageType);
193
194 if ($frameworkType === false) {
195 return false;
196 }
197
198 $locationPattern = $this->getLocationPattern($frameworkType);
199
200 return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
201 }
202
203 /**
204 * Finds a supported framework type if it exists and returns it
205 *
206 * @return string|false
207 */
208 protected function findFrameworkType(string $type)
209 {
210 krsort($this->supportedTypes);
211
212 foreach ($this->supportedTypes as $key => $val) {
213 if ($key === substr($type, 0, strlen($key))) {
214 return substr($type, 0, strlen($key));
215 }
216 }
217
218 return false;
219 }
220
221 /**
222 * Get the second part of the regular expression to check for support of a
223 * package type
224 */
225 protected function getLocationPattern(string $frameworkType): string
226 {
227 $pattern = null;
228 if (!empty($this->supportedTypes[$frameworkType])) {
229 $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
230 /** @var BaseInstaller $framework */
231 $framework = new $frameworkClass(new Package('dummy/pkg', '1.0.0.0', '1.0.0'), $this->composer, $this->getIO());
232 $locations = array_keys($framework->getLocations($frameworkType));
233 if ($locations) {
234 $pattern = '(' . implode('|', $locations) . ')';
235 }
236 }
237
238 return $pattern ?: '(\w+)';
239 }
240
241 private function getIO(): IOInterface
242 {
243 return $this->io;
244 }
245
246 /**
247 * Look for installers set to be disabled in composer's extra config and
248 * remove them from the list of supported installers.
249 *
250 * Globals:
251 * - true, "all", and "*" - disable all installers.
252 * - false - enable all installers (useful with
253 * wikimedia/composer-merge-plugin or similar)
254 */
255 protected function removeDisabledInstallers(): void
256 {
257 $extra = $this->composer->getPackage()->getExtra();
258
259 if (!isset($extra['installer-disable']) || $extra['installer-disable'] === false) {
260 // No installers are disabled
261 return;
262 }
263
264 // Get installers to disable
265 $disable = $extra['installer-disable'];
266
267 // Ensure $disabled is an array
268 if (!is_array($disable)) {
269 $disable = array($disable);
270 }
271
272 // Check which installers should be disabled
273 $all = array(true, "all", "*");
274 $intersect = array_intersect($all, $disable);
275 if (!empty($intersect)) {
276 // Disable all installers
277 $this->supportedTypes = array();
278 return;
279 }
280
281 // Disable specified installers
282 foreach ($disable as $key => $installer) {
283 if (is_string($installer) && key_exists($installer, $this->supportedTypes)) {
284 unset($this->supportedTypes[$installer]);
285 }
286 }
287 }
288 }
289