PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | vendor/composer/InstalledVersions.php +336 -594 0.6.0 → trunk View file →
@@ -1,654 +1,396 @@
1 1 <?php
2 2
3 +/*
4 + * This file is part of Composer.
5 + *
6 + * (c) Nils Adermann <[email protected]>
7 + * Jordi Boggiano <[email protected]>
8 + *
9 + * For the full copyright and license information, please view the LICENSE
10 + * file that was distributed with this source code.
11 + */
3 12
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 13 namespace Composer;
14 14
15 15 use Composer\Autoload\ClassLoader;
16 16 use Composer\Semver\VersionParser;
17 17
18 -
19 -
20 -
21 -
22 -
18 +/**
19 + * This class is copied in every Composer installed project and available to all
20 + *
21 + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
22 + *
23 + * To require its presence, you can require `composer-runtime-api ^2.0`
24 + *
25 + * @final
26 + */
23 27 class InstalledVersions
24 28 {
25 -private static $installed = array (
26 - 'root' =>
27 - array (
28 - 'pretty_version' => 'dev-main',
29 - 'version' => 'dev-main',
30 - 'aliases' =>
31 - array (
32 - ),
33 - 'reference' => 'ac2cfec95277e7980dfcf8dfde5cd858f1023e03',
34 - 'name' => 'extendify/extendify',
35 - ),
36 - 'versions' =>
37 - array (
38 - 'dealerdirect/phpcodesniffer-composer-installer' =>
39 - array (
40 - 'pretty_version' => 'v0.7.1',
41 - 'version' => '0.7.1.0',
42 - 'aliases' =>
43 - array (
44 - ),
45 - 'reference' => 'fe390591e0241955f22eb9ba327d137e501c771c',
46 - ),
47 - 'doctrine/instantiator' =>
48 - array (
49 - 'pretty_version' => '1.4.0',
50 - 'version' => '1.4.0.0',
51 - 'aliases' =>
52 - array (
53 - ),
54 - 'reference' => 'd56bf6102915de5702778fe20f2de3b2fe570b5b',
55 - ),
56 - 'extendify/extendify' =>
57 - array (
58 - 'pretty_version' => 'dev-main',
59 - 'version' => 'dev-main',
60 - 'aliases' =>
61 - array (
62 - ),
63 - 'reference' => 'ac2cfec95277e7980dfcf8dfde5cd858f1023e03',
64 - ),
65 - 'johnpbloch/wordpress-core' =>
66 - array (
67 - 'pretty_version' => '5.7.0',
68 - 'version' => '5.7.0.0',
69 - 'aliases' =>
70 - array (
71 - ),
72 - 'reference' => '8b057056692ca196aaa7a7ddd915f29426922c6d',
73 - ),
74 - 'myclabs/deep-copy' =>
75 - array (
76 - 'pretty_version' => '1.10.2',
77 - 'version' => '1.10.2.0',
78 - 'aliases' =>
79 - array (
80 - ),
81 - 'reference' => '776f831124e9c62e1a2c601ecc52e776d8bb7220',
82 - 'replaced' =>
83 - array (
84 - 0 => '1.10.2',
85 - ),
86 - ),
87 - 'nikic/php-parser' =>
88 - array (
89 - 'pretty_version' => 'v4.10.4',
90 - 'version' => '4.10.4.0',
91 - 'aliases' =>
92 - array (
93 - ),
94 - 'reference' => 'c6d052fc58cb876152f89f532b95a8d7907e7f0e',
95 - ),
96 - 'phar-io/manifest' =>
97 - array (
98 - 'pretty_version' => '2.0.1',
99 - 'version' => '2.0.1.0',
100 - 'aliases' =>
101 - array (
102 - ),
103 - 'reference' => '85265efd3af7ba3ca4b2a2c34dbfc5788dd29133',
104 - ),
105 - 'phar-io/version' =>
106 - array (
107 - 'pretty_version' => '3.1.0',
108 - 'version' => '3.1.0.0',
109 - 'aliases' =>
110 - array (
111 - ),
112 - 'reference' => 'bae7c545bef187884426f042434e561ab1ddb182',
113 - ),
114 - 'phpcompatibility/php-compatibility' =>
115 - array (
116 - 'pretty_version' => '9.3.5',
117 - 'version' => '9.3.5.0',
118 - 'aliases' =>
119 - array (
120 - ),
121 - 'reference' => '9fb324479acf6f39452e0655d2429cc0d3914243',
122 - ),
123 - 'phpcompatibility/phpcompatibility-paragonie' =>
124 - array (
125 - 'pretty_version' => '1.3.1',
126 - 'version' => '1.3.1.0',
127 - 'aliases' =>
128 - array (
129 - ),
130 - 'reference' => 'ddabec839cc003651f2ce695c938686d1086cf43',
131 - ),
132 - 'phpcompatibility/phpcompatibility-wp' =>
133 - array (
134 - 'pretty_version' => '2.1.1',
135 - 'version' => '2.1.1.0',
136 - 'aliases' =>
137 - array (
138 - ),
139 - 'reference' => 'b7dc0cd7a8f767ccac5e7637550ea1c50a67b09e',
140 - ),
141 - 'phpdocumentor/reflection-common' =>
142 - array (
143 - 'pretty_version' => '2.2.0',
144 - 'version' => '2.2.0.0',
145 - 'aliases' =>
146 - array (
147 - ),
148 - 'reference' => '1d01c49d4ed62f25aa84a747ad35d5a16924662b',
149 - ),
150 - 'phpdocumentor/reflection-docblock' =>
151 - array (
152 - 'pretty_version' => '5.2.2',
153 - 'version' => '5.2.2.0',
154 - 'aliases' =>
155 - array (
156 - ),
157 - 'reference' => '069a785b2141f5bcf49f3e353548dc1cce6df556',
158 - ),
159 - 'phpdocumentor/type-resolver' =>
160 - array (
161 - 'pretty_version' => '1.4.0',
162 - 'version' => '1.4.0.0',
163 - 'aliases' =>
164 - array (
165 - ),
166 - 'reference' => '6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0',
167 - ),
168 - 'phpspec/prophecy' =>
169 - array (
170 - 'pretty_version' => '1.13.0',
171 - 'version' => '1.13.0.0',
172 - 'aliases' =>
173 - array (
174 - ),
175 - 'reference' => 'be1996ed8adc35c3fd795488a653f4b518be70ea',
176 - ),
177 - 'phpunit/php-code-coverage' =>
178 - array (
179 - 'pretty_version' => '9.2.6',
180 - 'version' => '9.2.6.0',
181 - 'aliases' =>
182 - array (
183 - ),
184 - 'reference' => 'f6293e1b30a2354e8428e004689671b83871edde',
185 - ),
186 - 'phpunit/php-file-iterator' =>
187 - array (
188 - 'pretty_version' => '3.0.5',
189 - 'version' => '3.0.5.0',
190 - 'aliases' =>
191 - array (
192 - ),
193 - 'reference' => 'aa4be8575f26070b100fccb67faabb28f21f66f8',
194 - ),
195 - 'phpunit/php-invoker' =>
196 - array (
197 - 'pretty_version' => '3.1.1',
198 - 'version' => '3.1.1.0',
199 - 'aliases' =>
200 - array (
201 - ),
202 - 'reference' => '5a10147d0aaf65b58940a0b72f71c9ac0423cc67',
203 - ),
204 - 'phpunit/php-text-template' =>
205 - array (
206 - 'pretty_version' => '2.0.4',
207 - 'version' => '2.0.4.0',
208 - 'aliases' =>
209 - array (
210 - ),
211 - 'reference' => '5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28',
212 - ),
213 - 'phpunit/php-timer' =>
214 - array (
215 - 'pretty_version' => '5.0.3',
216 - 'version' => '5.0.3.0',
217 - 'aliases' =>
218 - array (
219 - ),
220 - 'reference' => '5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2',
221 - ),
222 - 'phpunit/phpunit' =>
223 - array (
224 - 'pretty_version' => '9.5.4',
225 - 'version' => '9.5.4.0',
226 - 'aliases' =>
227 - array (
228 - ),
229 - 'reference' => 'c73c6737305e779771147af66c96ca6a7ed8a741',
230 - ),
231 - 'sebastian/cli-parser' =>
232 - array (
233 - 'pretty_version' => '1.0.1',
234 - 'version' => '1.0.1.0',
235 - 'aliases' =>
236 - array (
237 - ),
238 - 'reference' => '442e7c7e687e42adc03470c7b668bc4b2402c0b2',
239 - ),
240 - 'sebastian/code-unit' =>
241 - array (
242 - 'pretty_version' => '1.0.8',
243 - 'version' => '1.0.8.0',
244 - 'aliases' =>
245 - array (
246 - ),
247 - 'reference' => '1fc9f64c0927627ef78ba436c9b17d967e68e120',
248 - ),
249 - 'sebastian/code-unit-reverse-lookup' =>
250 - array (
251 - 'pretty_version' => '2.0.3',
252 - 'version' => '2.0.3.0',
253 - 'aliases' =>
254 - array (
255 - ),
256 - 'reference' => 'ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5',
257 - ),
258 - 'sebastian/comparator' =>
259 - array (
260 - 'pretty_version' => '4.0.6',
261 - 'version' => '4.0.6.0',
262 - 'aliases' =>
263 - array (
264 - ),
265 - 'reference' => '55f4261989e546dc112258c7a75935a81a7ce382',
266 - ),
267 - 'sebastian/complexity' =>
268 - array (
269 - 'pretty_version' => '2.0.2',
270 - 'version' => '2.0.2.0',
271 - 'aliases' =>
272 - array (
273 - ),
274 - 'reference' => '739b35e53379900cc9ac327b2147867b8b6efd88',
275 - ),
276 - 'sebastian/diff' =>
277 - array (
278 - 'pretty_version' => '4.0.4',
279 - 'version' => '4.0.4.0',
280 - 'aliases' =>
281 - array (
282 - ),
283 - 'reference' => '3461e3fccc7cfdfc2720be910d3bd73c69be590d',
284 - ),
285 - 'sebastian/environment' =>
286 - array (
287 - 'pretty_version' => '5.1.3',
288 - 'version' => '5.1.3.0',
289 - 'aliases' =>
290 - array (
291 - ),
292 - 'reference' => '388b6ced16caa751030f6a69e588299fa09200ac',
293 - ),
294 - 'sebastian/exporter' =>
295 - array (
296 - 'pretty_version' => '4.0.3',
297 - 'version' => '4.0.3.0',
298 - 'aliases' =>
299 - array (
300 - ),
301 - 'reference' => 'd89cc98761b8cb5a1a235a6b703ae50d34080e65',
302 - ),
303 - 'sebastian/global-state' =>
304 - array (
305 - 'pretty_version' => '5.0.2',
306 - 'version' => '5.0.2.0',
307 - 'aliases' =>
308 - array (
309 - ),
310 - 'reference' => 'a90ccbddffa067b51f574dea6eb25d5680839455',
311 - ),
312 - 'sebastian/lines-of-code' =>
313 - array (
314 - 'pretty_version' => '1.0.3',
315 - 'version' => '1.0.3.0',
316 - 'aliases' =>
317 - array (
318 - ),
319 - 'reference' => 'c1c2e997aa3146983ed888ad08b15470a2e22ecc',
320 - ),
321 - 'sebastian/object-enumerator' =>
322 - array (
323 - 'pretty_version' => '4.0.4',
324 - 'version' => '4.0.4.0',
325 - 'aliases' =>
326 - array (
327 - ),
328 - 'reference' => '5c9eeac41b290a3712d88851518825ad78f45c71',
329 - ),
330 - 'sebastian/object-reflector' =>
331 - array (
332 - 'pretty_version' => '2.0.4',
333 - 'version' => '2.0.4.0',
334 - 'aliases' =>
335 - array (
336 - ),
337 - 'reference' => 'b4f479ebdbf63ac605d183ece17d8d7fe49c15c7',
338 - ),
339 - 'sebastian/recursion-context' =>
340 - array (
341 - 'pretty_version' => '4.0.4',
342 - 'version' => '4.0.4.0',
343 - 'aliases' =>
344 - array (
345 - ),
346 - 'reference' => 'cd9d8cf3c5804de4341c283ed787f099f5506172',
347 - ),
348 - 'sebastian/resource-operations' =>
349 - array (
350 - 'pretty_version' => '3.0.3',
351 - 'version' => '3.0.3.0',
352 - 'aliases' =>
353 - array (
354 - ),
355 - 'reference' => '0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8',
356 - ),
357 - 'sebastian/type' =>
358 - array (
359 - 'pretty_version' => '2.3.1',
360 - 'version' => '2.3.1.0',
361 - 'aliases' =>
362 - array (
363 - ),
364 - 'reference' => '81cd61ab7bbf2de744aba0ea61fae32f721df3d2',
365 - ),
366 - 'sebastian/version' =>
367 - array (
368 - 'pretty_version' => '3.0.2',
369 - 'version' => '3.0.2.0',
370 - 'aliases' =>
371 - array (
372 - ),
373 - 'reference' => 'c6c1022351a901512170118436c764e473f6de8c',
374 - ),
375 - 'squizlabs/php_codesniffer' =>
376 - array (
377 - 'pretty_version' => '3.6.0',
378 - 'version' => '3.6.0.0',
379 - 'aliases' =>
380 - array (
381 - ),
382 - 'reference' => 'ffced0d2c8fa8e6cdc4d695a743271fab6c38625',
383 - ),
384 - 'symfony/polyfill-ctype' =>
385 - array (
386 - 'pretty_version' => 'v1.22.1',
387 - 'version' => '1.22.1.0',
388 - 'aliases' =>
389 - array (
390 - ),
391 - 'reference' => 'c6c942b1ac76c82448322025e084cadc56048b4e',
392 - ),
393 - 'theseer/tokenizer' =>
394 - array (
395 - 'pretty_version' => '1.2.0',
396 - 'version' => '1.2.0.0',
397 - 'aliases' =>
398 - array (
399 - ),
400 - 'reference' => '75a63c33a8577608444246075ea0af0d052e452a',
401 - ),
402 - 'webmozart/assert' =>
403 - array (
404 - 'pretty_version' => '1.10.0',
405 - 'version' => '1.10.0.0',
406 - 'aliases' =>
407 - array (
408 - ),
409 - 'reference' => '6964c76c7804814a842473e0c8fd15bab0f18e25',
410 - ),
411 - 'wordpress/core-implementation' =>
412 - array (
413 - 'provided' =>
414 - array (
415 - 0 => '5.7.0',
416 - ),
417 - ),
418 - ),
419 -);
420 -private static $canGetVendors;
421 -private static $installedByVendor = array();
29 + /**
30 + * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
31 + * @internal
32 + */
33 + private static $selfDir = null;
422 34
35 + /**
36 + * @var mixed[]|null
37 + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
38 + */
39 + private static $installed;
423 40
41 + /**
42 + * @var bool
43 + */
44 + private static $installedIsLocalDir;
424 45
46 + /**
47 + * @var bool|null
48 + */
49 + private static $canGetVendors;
425 50
51 + /**
52 + * @var array[]
53 + * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
54 + */
55 + private static $installedByVendor = array();
426 56
57 + /**
58 + * Returns a list of all package names which are present, either by being installed, replaced or provided
59 + *
60 + * @return string[]
61 + * @psalm-return list<string>
62 + */
63 + public static function getInstalledPackages()
64 + {
65 + $packages = array();
66 + foreach (self::getInstalled() as $installed) {
67 + $packages[] = array_keys($installed['versions']);
68 + }
427 69
70 + if (1 === \count($packages)) {
71 + return $packages[0];
72 + }
428 73
429 -public static function getInstalledPackages()
430 -{
431 -$packages = array();
432 -foreach (self::getInstalled() as $installed) {
433 -$packages[] = array_keys($installed['versions']);
434 -}
74 + return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
75 + }
435 76
77 + /**
78 + * Returns a list of all package names with a specific type e.g. 'library'
79 + *
80 + * @param string $type
81 + * @return string[]
82 + * @psalm-return list<string>
83 + */
84 + public static function getInstalledPackagesByType($type)
85 + {
86 + $packagesByType = array();
436 87
437 -if (1 === \count($packages)) {
438 -return $packages[0];
439 -}
88 + foreach (self::getInstalled() as $installed) {
89 + foreach ($installed['versions'] as $name => $package) {
90 + if (isset($package['type']) && $package['type'] === $type) {
91 + $packagesByType[] = $name;
92 + }
93 + }
94 + }
440 95
441 -return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
442 -}
96 + return $packagesByType;
97 + }
443 98
99 + /**
100 + * Checks whether the given package is installed
101 + *
102 + * This also returns true if the package name is provided or replaced by another package
103 + *
104 + * @param string $packageName
105 + * @param bool $includeDevRequirements
106 + * @return bool
107 + */
108 + public static function isInstalled($packageName, $includeDevRequirements = true)
109 + {
110 + foreach (self::getInstalled() as $installed) {
111 + if (isset($installed['versions'][$packageName])) {
112 + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
113 + }
114 + }
444 115
116 + return false;
117 + }
445 118
119 + /**
120 + * Checks whether the given package satisfies a version constraint
121 + *
122 + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
123 + *
124 + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
125 + *
126 + * @param VersionParser $parser Install composer/semver to have access to this class and functionality
127 + * @param string $packageName
128 + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
129 + * @return bool
130 + */
131 + public static function satisfies(VersionParser $parser, $packageName, $constraint)
132 + {
133 + $constraint = $parser->parseConstraints((string) $constraint);
134 + $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
446 135
136 + return $provided->matches($constraint);
137 + }
447 138
139 + /**
140 + * Returns a version constraint representing all the range(s) which are installed for a given package
141 + *
142 + * It is easier to use this via isInstalled() with the $constraint argument if you need to check
143 + * whether a given version of a package is installed, and not just whether it exists
144 + *
145 + * @param string $packageName
146 + * @return string Version constraint usable with composer/semver
147 + */
148 + public static function getVersionRanges($packageName)
149 + {
150 + foreach (self::getInstalled() as $installed) {
151 + if (!isset($installed['versions'][$packageName])) {
152 + continue;
153 + }
448 154
155 + $ranges = array();
156 + if (isset($installed['versions'][$packageName]['pretty_version'])) {
157 + $ranges[] = $installed['versions'][$packageName]['pretty_version'];
158 + }
159 + if (array_key_exists('aliases', $installed['versions'][$packageName])) {
160 + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
161 + }
162 + if (array_key_exists('replaced', $installed['versions'][$packageName])) {
163 + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
164 + }
165 + if (array_key_exists('provided', $installed['versions'][$packageName])) {
166 + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
167 + }
449 168
169 + return implode(' || ', $ranges);
170 + }
450 171
172 + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
173 + }
451 174
452 -public static function isInstalled($packageName)
453 -{
454 -foreach (self::getInstalled() as $installed) {
455 -if (isset($installed['versions'][$packageName])) {
456 -return true;
457 -}
458 -}
175 + /**
176 + * @param string $packageName
177 + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
178 + */
179 + public static function getVersion($packageName)
180 + {
181 + foreach (self::getInstalled() as $installed) {
182 + if (!isset($installed['versions'][$packageName])) {
183 + continue;
184 + }
459 185
460 -return false;
461 -}
186 + if (!isset($installed['versions'][$packageName]['version'])) {
187 + return null;
188 + }
462 189
190 + return $installed['versions'][$packageName]['version'];
191 + }
463 192
193 + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
194 + }
464 195
196 + /**
197 + * @param string $packageName
198 + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
199 + */
200 + public static function getPrettyVersion($packageName)
201 + {
202 + foreach (self::getInstalled() as $installed) {
203 + if (!isset($installed['versions'][$packageName])) {
204 + continue;
205 + }
465 206
207 + if (!isset($installed['versions'][$packageName]['pretty_version'])) {
208 + return null;
209 + }
466 210
211 + return $installed['versions'][$packageName]['pretty_version'];
212 + }
467 213
214 + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
215 + }
468 216
217 + /**
218 + * @param string $packageName
219 + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
220 + */
221 + public static function getReference($packageName)
222 + {
223 + foreach (self::getInstalled() as $installed) {
224 + if (!isset($installed['versions'][$packageName])) {
225 + continue;
226 + }
469 227
228 + if (!isset($installed['versions'][$packageName]['reference'])) {
229 + return null;
230 + }
470 231
232 + return $installed['versions'][$packageName]['reference'];
233 + }
471 234
235 + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
236 + }
472 237
238 + /**
239 + * @param string $packageName
240 + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
241 + */
242 + public static function getInstallPath($packageName)
243 + {
244 + foreach (self::getInstalled() as $installed) {
245 + if (!isset($installed['versions'][$packageName])) {
246 + continue;
247 + }
473 248
249 + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
250 + }
474 251
252 + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
253 + }
475 254
476 -public static function satisfies(VersionParser $parser, $packageName, $constraint)
477 -{
478 -$constraint = $parser->parseConstraints($constraint);
479 -$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
255 + /**
256 + * @return array
257 + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
258 + */
259 + public static function getRootPackage()
260 + {
261 + $installed = self::getInstalled();
480 262
481 -return $provided->matches($constraint);
482 -}
263 + return $installed[0]['root'];
264 + }
483 265
266 + /**
267 + * Returns the raw installed.php data for custom implementations
268 + *
269 + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
270 + * @return array[]
271 + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
272 + */
273 + public static function getRawData()
274 + {
275 + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
484 276
277 + if (null === self::$installed) {
278 + // only require the installed.php file if this file is loaded from its dumped location,
279 + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
280 + if (substr(__DIR__, -8, 1) !== 'C') {
281 + self::$installed = include __DIR__ . '/installed.php';
282 + } else {
283 + self::$installed = array();
284 + }
285 + }
485 286
287 + return self::$installed;
288 + }
486 289
290 + /**
291 + * Returns the raw data of all installed.php which are currently loaded for custom implementations
292 + *
293 + * @return array[]
294 + * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
295 + */
296 + public static function getAllRawData()
297 + {
298 + return self::getInstalled();
299 + }
487 300
301 + /**
302 + * Lets you reload the static array from another file
303 + *
304 + * This is only useful for complex integrations in which a project needs to use
305 + * this class but then also needs to execute another project's autoloader in process,
306 + * and wants to ensure both projects have access to their version of installed.php.
307 + *
308 + * A typical case would be PHPUnit, where it would need to make sure it reads all
309 + * the data it needs from this class, then call reload() with
310 + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
311 + * the project in which it runs can then also use this class safely, without
312 + * interference between PHPUnit's dependencies and the project's dependencies.
313 + *
314 + * @param array[] $data A vendor/composer/installed.php data set
315 + * @return void
316 + *
317 + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
318 + */
319 + public static function reload($data)
320 + {
321 + self::$installed = $data;
322 + self::$installedByVendor = array();
488 323
324 + // when using reload, we disable the duplicate protection to ensure that self::$installed data is
325 + // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
326 + // so we have to assume it does not, and that may result in duplicate data being returned when listing
327 + // all installed packages for example
328 + self::$installedIsLocalDir = false;
329 + }
489 330
331 + /**
332 + * @return string
333 + */
334 + private static function getSelfDir()
335 + {
336 + if (self::$selfDir === null) {
337 + self::$selfDir = strtr(__DIR__, '\\', '/');
338 + }
490 339
340 + return self::$selfDir;
341 + }
491 342
343 + /**
344 + * @return array[]
345 + * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
346 + */
347 + private static function getInstalled()
348 + {
349 + if (null === self::$canGetVendors) {
350 + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
351 + }
492 352
493 -public static function getVersionRanges($packageName)
494 -{
495 -foreach (self::getInstalled() as $installed) {
496 -if (!isset($installed['versions'][$packageName])) {
497 -continue;
498 -}
353 + $installed = array();
354 + $copiedLocalDir = false;
499 355
500 -$ranges = array();
501 -if (isset($installed['versions'][$packageName]['pretty_version'])) {
502 -$ranges[] = $installed['versions'][$packageName]['pretty_version'];
503 -}
504 -if (array_key_exists('aliases', $installed['versions'][$packageName])) {
505 -$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
506 -}
507 -if (array_key_exists('replaced', $installed['versions'][$packageName])) {
508 -$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
509 -}
510 -if (array_key_exists('provided', $installed['versions'][$packageName])) {
511 -$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
512 -}
356 + if (self::$canGetVendors) {
357 + $selfDir = self::getSelfDir();
358 + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
359 + $vendorDir = strtr($vendorDir, '\\', '/');
360 + if (isset(self::$installedByVendor[$vendorDir])) {
361 + $installed[] = self::$installedByVendor[$vendorDir];
362 + } elseif (is_file($vendorDir.'/composer/installed.php')) {
363 + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
364 + $required = require $vendorDir.'/composer/installed.php';
365 + self::$installedByVendor[$vendorDir] = $required;
366 + $installed[] = $required;
367 + if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
368 + self::$installed = $required;
369 + self::$installedIsLocalDir = true;
370 + }
371 + }
372 + if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
373 + $copiedLocalDir = true;
374 + }
375 + }
376 + }
513 377
514 -return implode(' || ', $ranges);
515 -}
378 + if (null === self::$installed) {
379 + // only require the installed.php file if this file is loaded from its dumped location,
380 + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
381 + if (substr(__DIR__, -8, 1) !== 'C') {
382 + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
383 + $required = require __DIR__ . '/installed.php';
384 + self::$installed = $required;
385 + } else {
386 + self::$installed = array();
387 + }
388 + }
516 389
517 -throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
518 -}
390 + if (self::$installed !== array() && !$copiedLocalDir) {
391 + $installed[] = self::$installed;
392 + }
519 393
520 -
521 -
522 -
523 -
524 -public static function getVersion($packageName)
525 -{
526 -foreach (self::getInstalled() as $installed) {
527 -if (!isset($installed['versions'][$packageName])) {
528 -continue;
529 -}
530 -
531 -if (!isset($installed['versions'][$packageName]['version'])) {
532 -return null;
533 -}
534 -
535 -return $installed['versions'][$packageName]['version'];
536 -}
537 -
538 -throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
539 -}
540 -
541 -
542 -
543 -
544 -
545 -public static function getPrettyVersion($packageName)
546 -{
547 -foreach (self::getInstalled() as $installed) {
548 -if (!isset($installed['versions'][$packageName])) {
549 -continue;
550 -}
551 -
552 -if (!isset($installed['versions'][$packageName]['pretty_version'])) {
553 -return null;
554 -}
555 -
556 -return $installed['versions'][$packageName]['pretty_version'];
557 -}
558 -
559 -throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
560 -}
561 -
562 -
563 -
564 -
565 -
566 -public static function getReference($packageName)
567 -{
568 -foreach (self::getInstalled() as $installed) {
569 -if (!isset($installed['versions'][$packageName])) {
570 -continue;
571 -}
572 -
573 -if (!isset($installed['versions'][$packageName]['reference'])) {
574 -return null;
575 -}
576 -
577 -return $installed['versions'][$packageName]['reference'];
578 -}
579 -
580 -throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
581 -}
582 -
583 -
584 -
585 -
586 -
587 -public static function getRootPackage()
588 -{
589 -$installed = self::getInstalled();
590 -
591 -return $installed[0]['root'];
592 -}
593 -
594 -
595 -
596 -
597 -
598 -
599 -
600 -public static function getRawData()
601 -{
602 -return self::$installed;
603 -}
604 -
605 -
606 -
607 -
608 -
609 -
610 -
611 -
612 -
613 -
614 -
615 -
616 -
617 -
618 -
619 -
620 -
621 -
622 -
623 -public static function reload($data)
624 -{
625 -self::$installed = $data;
626 -self::$installedByVendor = array();
627 -}
628 -
629 -
630 -
631 -
632 -private static function getInstalled()
633 -{
634 -if (null === self::$canGetVendors) {
635 -self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
636 -}
637 -
638 -$installed = array();
639 -
640 -if (self::$canGetVendors) {
641 -foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
642 -if (isset(self::$installedByVendor[$vendorDir])) {
643 -$installed[] = self::$installedByVendor[$vendorDir];
644 -} elseif (is_file($vendorDir.'/composer/installed.php')) {
645 -$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
646 -}
647 -}
648 -}
649 -
650 -$installed[] = self::$installed;
651 -
652 -return $installed;
653 -}
394 + return $installed;
395 + }
654 396 }