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.22.x-dev',
31    'version' => '1.22.9999999.9999999-dev',
32    'aliases' =>
33    array (
34    ),
35    'reference' => '70c0e03a7f16e199a3dc6c79fcc5b7e3edaf6886',
36    'name' => 'combostrap/combo',
37  ),
38  'versions' =>
39  array (
40    'antlr/antlr4-php-runtime' =>
41    array (
42      'pretty_version' => '0.5.0',
43      'version' => '0.5.0.0',
44      'aliases' =>
45      array (
46      ),
47      'reference' => '0cb16628b575b50bd087a81d11bd961ac3b8e9e9',
48    ),
49    'combostrap/combo' =>
50    array (
51      'pretty_version' => '1.22.x-dev',
52      'version' => '1.22.9999999.9999999-dev',
53      'aliases' =>
54      array (
55      ),
56      'reference' => '70c0e03a7f16e199a3dc6c79fcc5b7e3edaf6886',
57    ),
58    'dragonmantank/cron-expression' =>
59    array (
60      'pretty_version' => 'v1.2.1',
61      'version' => '1.2.1.0',
62      'aliases' =>
63      array (
64      ),
65      'reference' => '9504fa9ea681b586028adaaa0877db4aecf32bad',
66    ),
67    'hidehalo/nanoid-php' =>
68    array (
69      'pretty_version' => '1.1.8',
70      'version' => '1.1.8.0',
71      'aliases' =>
72      array (
73      ),
74      'reference' => '14187ab7a5affa34078b6a54df94176bb7a21227',
75    ),
76    'paragonie/random_compat' =>
77    array (
78      'pretty_version' => 'v9.99.100',
79      'version' => '9.99.100.0',
80      'aliases' =>
81      array (
82      ),
83      'reference' => '996434e5492cb4c3edcb9168db6fbb1359ef965a',
84    ),
85  ),
86);
87private static $canGetVendors;
88private static $installedByVendor = array();
89
90
91
92
93
94
95
96public static function getInstalledPackages()
97{
98$packages = array();
99foreach (self::getInstalled() as $installed) {
100$packages[] = array_keys($installed['versions']);
101}
102
103if (1 === \count($packages)) {
104return $packages[0];
105}
106
107return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
108}
109
110
111
112
113
114
115
116
117
118public static function isInstalled($packageName)
119{
120foreach (self::getInstalled() as $installed) {
121if (isset($installed['versions'][$packageName])) {
122return true;
123}
124}
125
126return false;
127}
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142public static function satisfies(VersionParser $parser, $packageName, $constraint)
143{
144$constraint = $parser->parseConstraints($constraint);
145$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
146
147return $provided->matches($constraint);
148}
149
150
151
152
153
154
155
156
157
158
159public static function getVersionRanges($packageName)
160{
161foreach (self::getInstalled() as $installed) {
162if (!isset($installed['versions'][$packageName])) {
163continue;
164}
165
166$ranges = array();
167if (isset($installed['versions'][$packageName]['pretty_version'])) {
168$ranges[] = $installed['versions'][$packageName]['pretty_version'];
169}
170if (array_key_exists('aliases', $installed['versions'][$packageName])) {
171$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
172}
173if (array_key_exists('replaced', $installed['versions'][$packageName])) {
174$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
175}
176if (array_key_exists('provided', $installed['versions'][$packageName])) {
177$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
178}
179
180return implode(' || ', $ranges);
181}
182
183throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
184}
185
186
187
188
189
190public static function getVersion($packageName)
191{
192foreach (self::getInstalled() as $installed) {
193if (!isset($installed['versions'][$packageName])) {
194continue;
195}
196
197if (!isset($installed['versions'][$packageName]['version'])) {
198return null;
199}
200
201return $installed['versions'][$packageName]['version'];
202}
203
204throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
205}
206
207
208
209
210
211public static function getPrettyVersion($packageName)
212{
213foreach (self::getInstalled() as $installed) {
214if (!isset($installed['versions'][$packageName])) {
215continue;
216}
217
218if (!isset($installed['versions'][$packageName]['pretty_version'])) {
219return null;
220}
221
222return $installed['versions'][$packageName]['pretty_version'];
223}
224
225throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
226}
227
228
229
230
231
232public static function getReference($packageName)
233{
234foreach (self::getInstalled() as $installed) {
235if (!isset($installed['versions'][$packageName])) {
236continue;
237}
238
239if (!isset($installed['versions'][$packageName]['reference'])) {
240return null;
241}
242
243return $installed['versions'][$packageName]['reference'];
244}
245
246throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
247}
248
249
250
251
252
253public static function getRootPackage()
254{
255$installed = self::getInstalled();
256
257return $installed[0]['root'];
258}
259
260
261
262
263
264
265
266
267public static function getRawData()
268{
269@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);
270
271return self::$installed;
272}
273
274
275
276
277
278
279
280public static function getAllRawData()
281{
282return self::getInstalled();
283}
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303public static function reload($data)
304{
305self::$installed = $data;
306self::$installedByVendor = array();
307}
308
309
310
311
312
313private static function getInstalled()
314{
315if (null === self::$canGetVendors) {
316self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
317}
318
319$installed = array();
320
321if (self::$canGetVendors) {
322foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
323if (isset(self::$installedByVendor[$vendorDir])) {
324$installed[] = self::$installedByVendor[$vendorDir];
325} elseif (is_file($vendorDir.'/composer/installed.php')) {
326$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
327}
328}
329}
330
331$installed[] = self::$installed;
332
333return $installed;
334}
335}
336