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
23
24
25class InstalledVersions
26{
27private static $installed = array (
28  'root' =>
29  array (
30    'pretty_version' => '1.25.x-dev',
31    'version' => '1.25.9999999.9999999-dev',
32    'aliases' =>
33    array (
34    ),
35    'reference' => 'e1d6dd02e975fb270ebff01372a934b172dfefbd',
36    'name' => 'combostrap/combo',
37  ),
38  'versions' =>
39  array (
40    'antlr/antlr4-php-runtime' =>
41    array (
42      'pretty_version' => '0.5.1',
43      'version' => '0.5.1.0',
44      'aliases' =>
45      array (
46      ),
47      'reference' => '73790bc994cec4b18a414865234ab0db198b065d',
48    ),
49    'carica/phpcss' =>
50    array (
51      'pretty_version' => '2.0.0',
52      'version' => '2.0.0.0',
53      'aliases' =>
54      array (
55      ),
56      'reference' => '944cdd0cf21655ceb1bd3262dee9b33602020c09',
57    ),
58    'combostrap/combo' =>
59    array (
60      'pretty_version' => '1.25.x-dev',
61      'version' => '1.25.9999999.9999999-dev',
62      'aliases' =>
63      array (
64      ),
65      'reference' => 'e1d6dd02e975fb270ebff01372a934b172dfefbd',
66    ),
67    'dragonmantank/cron-expression' =>
68    array (
69      'pretty_version' => 'v1.2.1',
70      'version' => '1.2.1.0',
71      'aliases' =>
72      array (
73      ),
74      'reference' => '9504fa9ea681b586028adaaa0877db4aecf32bad',
75    ),
76    'facebook/webdriver' =>
77    array (
78      'replaced' =>
79      array (
80        0 => '*',
81      ),
82    ),
83    'hidehalo/nanoid-php' =>
84    array (
85      'pretty_version' => '1.1.8',
86      'version' => '1.1.8.0',
87      'aliases' =>
88      array (
89      ),
90      'reference' => '14187ab7a5affa34078b6a54df94176bb7a21227',
91    ),
92    'paragonie/random_compat' =>
93    array (
94      'pretty_version' => 'v9.99.100',
95      'version' => '9.99.100.0',
96      'aliases' =>
97      array (
98      ),
99      'reference' => '996434e5492cb4c3edcb9168db6fbb1359ef965a',
100    ),
101    'php-webdriver/webdriver' =>
102    array (
103      'pretty_version' => '1.12.1',
104      'version' => '1.12.1.0',
105      'aliases' =>
106      array (
107      ),
108      'reference' => 'b27ddf458d273c7d4602106fcaf978aa0b7fe15a',
109    ),
110    'salesforce/handlebars-php' =>
111    array (
112      'pretty_version' => '3.0.1',
113      'version' => '3.0.1.0',
114      'aliases' =>
115      array (
116      ),
117      'reference' => 'd3a0552d85472249617ef6b56197c844d62d2ac3',
118    ),
119    'symfony/deprecation-contracts' =>
120    array (
121      'pretty_version' => 'v2.5.2',
122      'version' => '2.5.2.0',
123      'aliases' =>
124      array (
125      ),
126      'reference' => 'e8b495ea28c1d97b5e0c121748d6f9b53d075c66',
127    ),
128    'symfony/polyfill-ctype' =>
129    array (
130      'pretty_version' => 'v1.27.0',
131      'version' => '1.27.0.0',
132      'aliases' =>
133      array (
134      ),
135      'reference' => '5bbc823adecdae860bb64756d639ecfec17b050a',
136    ),
137    'symfony/polyfill-mbstring' =>
138    array (
139      'pretty_version' => 'v1.25.0',
140      'version' => '1.25.0.0',
141      'aliases' =>
142      array (
143      ),
144      'reference' => '0abb51d2f102e00a4eefcf46ba7fec406d245825',
145    ),
146    'symfony/polyfill-php80' =>
147    array (
148      'pretty_version' => 'v1.25.0',
149      'version' => '1.25.0.0',
150      'aliases' =>
151      array (
152      ),
153      'reference' => '4407588e0d3f1f52efb65fbe92babe41f37fe50c',
154    ),
155    'symfony/process' =>
156    array (
157      'pretty_version' => 'v5.4.8',
158      'version' => '5.4.8.0',
159      'aliases' =>
160      array (
161      ),
162      'reference' => '597f3fff8e3e91836bb0bd38f5718b56ddbde2f3',
163    ),
164    'symfony/yaml' =>
165    array (
166      'pretty_version' => 'v5.4.21',
167      'version' => '5.4.21.0',
168      'aliases' =>
169      array (
170      ),
171      'reference' => '3713e20d93e46e681e51605d213027e48dab3469',
172    ),
173  ),
174);
175private static $canGetVendors;
176private static $installedByVendor = array();
177
178
179
180
181
182
183
184public static function getInstalledPackages()
185{
186$packages = array();
187foreach (self::getInstalled() as $installed) {
188$packages[] = array_keys($installed['versions']);
189}
190
191if (1 === \count($packages)) {
192return $packages[0];
193}
194
195return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
196}
197
198
199
200
201
202
203
204
205
206public static function isInstalled($packageName)
207{
208foreach (self::getInstalled() as $installed) {
209if (isset($installed['versions'][$packageName])) {
210return true;
211}
212}
213
214return false;
215}
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230public static function satisfies(VersionParser $parser, $packageName, $constraint)
231{
232$constraint = $parser->parseConstraints($constraint);
233$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
234
235return $provided->matches($constraint);
236}
237
238
239
240
241
242
243
244
245
246
247public static function getVersionRanges($packageName)
248{
249foreach (self::getInstalled() as $installed) {
250if (!isset($installed['versions'][$packageName])) {
251continue;
252}
253
254$ranges = array();
255if (isset($installed['versions'][$packageName]['pretty_version'])) {
256$ranges[] = $installed['versions'][$packageName]['pretty_version'];
257}
258if (array_key_exists('aliases', $installed['versions'][$packageName])) {
259$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
260}
261if (array_key_exists('replaced', $installed['versions'][$packageName])) {
262$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
263}
264if (array_key_exists('provided', $installed['versions'][$packageName])) {
265$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
266}
267
268return implode(' || ', $ranges);
269}
270
271throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
272}
273
274
275
276
277
278public static function getVersion($packageName)
279{
280foreach (self::getInstalled() as $installed) {
281if (!isset($installed['versions'][$packageName])) {
282continue;
283}
284
285if (!isset($installed['versions'][$packageName]['version'])) {
286return null;
287}
288
289return $installed['versions'][$packageName]['version'];
290}
291
292throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
293}
294
295
296
297
298
299public static function getPrettyVersion($packageName)
300{
301foreach (self::getInstalled() as $installed) {
302if (!isset($installed['versions'][$packageName])) {
303continue;
304}
305
306if (!isset($installed['versions'][$packageName]['pretty_version'])) {
307return null;
308}
309
310return $installed['versions'][$packageName]['pretty_version'];
311}
312
313throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
314}
315
316
317
318
319
320public static function getReference($packageName)
321{
322foreach (self::getInstalled() as $installed) {
323if (!isset($installed['versions'][$packageName])) {
324continue;
325}
326
327if (!isset($installed['versions'][$packageName]['reference'])) {
328return null;
329}
330
331return $installed['versions'][$packageName]['reference'];
332}
333
334throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
335}
336
337
338
339
340
341public static function getRootPackage()
342{
343$installed = self::getInstalled();
344
345return $installed[0]['root'];
346}
347
348
349
350
351
352
353
354
355public static function getRawData()
356{
357@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);
358
359return self::$installed;
360}
361
362
363
364
365
366
367
368public static function getAllRawData()
369{
370return self::getInstalled();
371}
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391public static function reload($data)
392{
393self::$installed = $data;
394self::$installedByVendor = array();
395}
396
397
398
399
400
401private static function getInstalled()
402{
403if (null === self::$canGetVendors) {
404self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
405}
406
407$installed = array();
408
409if (self::$canGetVendors) {
410foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
411if (isset(self::$installedByVendor[$vendorDir])) {
412$installed[] = self::$installedByVendor[$vendorDir];
413} elseif (is_file($vendorDir.'/composer/installed.php')) {
414$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
415}
416}
417}
418
419$installed[] = self::$installed;
420
421return $installed;
422}
423}
424