1<?php
2
3
4
5
6
7
8
9
10
11
12
13namespace Composer;
14
15use Composer\Autoload\ClassLoader;
16use Composer\Semver\VersionParser;
17
18
19
20
21
22
23class InstalledVersions
24{
25private static $installed = array (
26  'root' =>
27  array (
28    'pretty_version' => 'dev-master',
29    'version' => 'dev-master',
30    'aliases' =>
31    array (
32    ),
33    'reference' => '614b390342771c50886f51d18321295bcb06eb6a',
34    'name' => '__root__',
35  ),
36  'versions' =>
37  array (
38    '__root__' =>
39    array (
40      'pretty_version' => 'dev-master',
41      'version' => 'dev-master',
42      'aliases' =>
43      array (
44      ),
45      'reference' => '614b390342771c50886f51d18321295bcb06eb6a',
46    ),
47    'firebase/php-jwt' =>
48    array (
49      'pretty_version' => 'v6.1.2',
50      'version' => '6.1.2.0',
51      'aliases' =>
52      array (
53      ),
54      'reference' => 'c297139da7c6873dbd67cbd1093f09ec0bbd0c50',
55    ),
56    'google/apiclient' =>
57    array (
58      'pretty_version' => 'v2.12.4',
59      'version' => '2.12.4.0',
60      'aliases' =>
61      array (
62      ),
63      'reference' => '702eed9ae7022ba20dc7118c8161060cb50ee9f8',
64    ),
65    'google/apiclient-services' =>
66    array (
67      'pretty_version' => 'v0.246.0',
68      'version' => '0.246.0.0',
69      'aliases' =>
70      array (
71      ),
72      'reference' => '33aef1ccce34799a1124c39951fed8ad0b16aced',
73    ),
74    'google/auth' =>
75    array (
76      'pretty_version' => 'v1.21.0',
77      'version' => '1.21.0.0',
78      'aliases' =>
79      array (
80      ),
81      'reference' => '73392bad2eb6852eea9084b6bbdec752515cb849',
82    ),
83    'guzzlehttp/guzzle' =>
84    array (
85      'pretty_version' => '6.5.5',
86      'version' => '6.5.5.0',
87      'aliases' =>
88      array (
89      ),
90      'reference' => '9d4290de1cfd701f38099ef7e183b64b4b7b0c5e',
91    ),
92    'guzzlehttp/promises' =>
93    array (
94      'pretty_version' => '1.5.1',
95      'version' => '1.5.1.0',
96      'aliases' =>
97      array (
98      ),
99      'reference' => 'fe752aedc9fd8fcca3fe7ad05d419d32998a06da',
100    ),
101    'guzzlehttp/psr7' =>
102    array (
103      'pretty_version' => '1.8.5',
104      'version' => '1.8.5.0',
105      'aliases' =>
106      array (
107      ),
108      'reference' => '337e3ad8e5716c15f9657bd214d16cc5e69df268',
109    ),
110    'monolog/monolog' =>
111    array (
112      'pretty_version' => '2.5.0',
113      'version' => '2.5.0.0',
114      'aliases' =>
115      array (
116      ),
117      'reference' => '4192345e260f1d51b365536199744b987e160edc',
118    ),
119    'paragonie/constant_time_encoding' =>
120    array (
121      'pretty_version' => 'v2.5.0',
122      'version' => '2.5.0.0',
123      'aliases' =>
124      array (
125      ),
126      'reference' => '9229e15f2e6ba772f0c55dd6986c563b937170a8',
127    ),
128    'paragonie/random_compat' =>
129    array (
130      'pretty_version' => 'v9.99.100',
131      'version' => '9.99.100.0',
132      'aliases' =>
133      array (
134      ),
135      'reference' => '996434e5492cb4c3edcb9168db6fbb1359ef965a',
136    ),
137    'phpseclib/phpseclib' =>
138    array (
139      'pretty_version' => '3.0.14',
140      'version' => '3.0.14.0',
141      'aliases' =>
142      array (
143      ),
144      'reference' => '2f0b7af658cbea265cbb4a791d6c29a6613f98ef',
145    ),
146    'psr/cache' =>
147    array (
148      'pretty_version' => '1.0.1',
149      'version' => '1.0.1.0',
150      'aliases' =>
151      array (
152      ),
153      'reference' => 'd11b50ad223250cf17b86e38383413f5a6764bf8',
154    ),
155    'psr/http-message' =>
156    array (
157      'pretty_version' => '1.0.1',
158      'version' => '1.0.1.0',
159      'aliases' =>
160      array (
161      ),
162      'reference' => 'f6561bf28d520154e4b0ec72be95418abe6d9363',
163    ),
164    'psr/http-message-implementation' =>
165    array (
166      'provided' =>
167      array (
168        0 => '1.0',
169      ),
170    ),
171    'psr/log' =>
172    array (
173      'pretty_version' => '1.1.4',
174      'version' => '1.1.4.0',
175      'aliases' =>
176      array (
177      ),
178      'reference' => 'd49695b909c3b7628b6289db5479a1c204601f11',
179    ),
180    'psr/log-implementation' =>
181    array (
182      'provided' =>
183      array (
184        0 => '1.0.0 || 2.0.0 || 3.0.0',
185      ),
186    ),
187    'ralouphie/getallheaders' =>
188    array (
189      'pretty_version' => '3.0.3',
190      'version' => '3.0.3.0',
191      'aliases' =>
192      array (
193      ),
194      'reference' => '120b605dfeb996808c31b6477290a714d356e822',
195    ),
196    'symfony/polyfill-intl-idn' =>
197    array (
198      'pretty_version' => 'v1.25.0',
199      'version' => '1.25.0.0',
200      'aliases' =>
201      array (
202      ),
203      'reference' => '749045c69efb97c70d25d7463abba812e91f3a44',
204    ),
205    'symfony/polyfill-intl-normalizer' =>
206    array (
207      'pretty_version' => 'v1.25.0',
208      'version' => '1.25.0.0',
209      'aliases' =>
210      array (
211      ),
212      'reference' => '8590a5f561694770bdcd3f9b5c69dde6945028e8',
213    ),
214    'symfony/polyfill-php72' =>
215    array (
216      'pretty_version' => 'v1.25.0',
217      'version' => '1.25.0.0',
218      'aliases' =>
219      array (
220      ),
221      'reference' => '9a142215a36a3888e30d0a9eeea9766764e96976',
222    ),
223  ),
224);
225private static $canGetVendors;
226private static $installedByVendor = array();
227
228
229
230
231
232
233
234public static function getInstalledPackages()
235{
236$packages = array();
237foreach (self::getInstalled() as $installed) {
238$packages[] = array_keys($installed['versions']);
239}
240
241
242if (1 === \count($packages)) {
243return $packages[0];
244}
245
246return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
247}
248
249
250
251
252
253
254
255
256
257public static function isInstalled($packageName)
258{
259foreach (self::getInstalled() as $installed) {
260if (isset($installed['versions'][$packageName])) {
261return true;
262}
263}
264
265return false;
266}
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281public static function satisfies(VersionParser $parser, $packageName, $constraint)
282{
283$constraint = $parser->parseConstraints($constraint);
284$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
285
286return $provided->matches($constraint);
287}
288
289
290
291
292
293
294
295
296
297
298public static function getVersionRanges($packageName)
299{
300foreach (self::getInstalled() as $installed) {
301if (!isset($installed['versions'][$packageName])) {
302continue;
303}
304
305$ranges = array();
306if (isset($installed['versions'][$packageName]['pretty_version'])) {
307$ranges[] = $installed['versions'][$packageName]['pretty_version'];
308}
309if (array_key_exists('aliases', $installed['versions'][$packageName])) {
310$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
311}
312if (array_key_exists('replaced', $installed['versions'][$packageName])) {
313$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
314}
315if (array_key_exists('provided', $installed['versions'][$packageName])) {
316$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
317}
318
319return implode(' || ', $ranges);
320}
321
322throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
323}
324
325
326
327
328
329public static function getVersion($packageName)
330{
331foreach (self::getInstalled() as $installed) {
332if (!isset($installed['versions'][$packageName])) {
333continue;
334}
335
336if (!isset($installed['versions'][$packageName]['version'])) {
337return null;
338}
339
340return $installed['versions'][$packageName]['version'];
341}
342
343throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
344}
345
346
347
348
349
350public static function getPrettyVersion($packageName)
351{
352foreach (self::getInstalled() as $installed) {
353if (!isset($installed['versions'][$packageName])) {
354continue;
355}
356
357if (!isset($installed['versions'][$packageName]['pretty_version'])) {
358return null;
359}
360
361return $installed['versions'][$packageName]['pretty_version'];
362}
363
364throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
365}
366
367
368
369
370
371public static function getReference($packageName)
372{
373foreach (self::getInstalled() as $installed) {
374if (!isset($installed['versions'][$packageName])) {
375continue;
376}
377
378if (!isset($installed['versions'][$packageName]['reference'])) {
379return null;
380}
381
382return $installed['versions'][$packageName]['reference'];
383}
384
385throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
386}
387
388
389
390
391
392public static function getRootPackage()
393{
394$installed = self::getInstalled();
395
396return $installed[0]['root'];
397}
398
399
400
401
402
403
404
405public static function getRawData()
406{
407return self::$installed;
408}
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428public static function reload($data)
429{
430self::$installed = $data;
431self::$installedByVendor = array();
432}
433
434
435
436
437private static function getInstalled()
438{
439if (null === self::$canGetVendors) {
440self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
441}
442
443$installed = array();
444
445if (self::$canGetVendors) {
446
447foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
448if (isset(self::$installedByVendor[$vendorDir])) {
449$installed[] = self::$installedByVendor[$vendorDir];
450} elseif (is_file($vendorDir.'/composer/installed.php')) {
451$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
452}
453}
454}
455
456$installed[] = self::$installed;
457
458return $installed;
459}
460}
461