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' => '4ee6ddae660f9ec72c1f6e2ddb72d6b29d6d8900',
34    'name' => 'splitbrain/dokuwiki',
35  ),
36  'versions' =>
37  array (
38    'aziraphale/email-address-validator' =>
39    array (
40      'pretty_version' => '2.0.1',
41      'version' => '2.0.1.0',
42      'aliases' =>
43      array (
44      ),
45      'reference' => 'fa25bc22c1c0b6491657c91473fae3e40719a650',
46    ),
47    'geshi/geshi' =>
48    array (
49      'pretty_version' => 'dev-master',
50      'version' => 'dev-master',
51      'aliases' =>
52      array (
53        0 => '1.0.x-dev',
54        1 => '9999999-dev',
55      ),
56      'reference' => '3c12a7931d509c5e3557c5ed44c9a32e9c917c7d',
57    ),
58    'marcusschwarz/lesserphp' =>
59    array (
60      'pretty_version' => 'v0.5.5',
61      'version' => '0.5.5.0',
62      'aliases' =>
63      array (
64      ),
65      'reference' => '77ba82b5218ff228267d3b0e5ec8697be75e86a7',
66    ),
67    'openpsa/universalfeedcreator' =>
68    array (
69      'pretty_version' => 'v1.8.4',
70      'version' => '1.8.4.0',
71      'aliases' =>
72      array (
73      ),
74      'reference' => '099817dc9efef33ca2382b04daf9e191b77fed13',
75    ),
76    'phpseclib/phpseclib' =>
77    array (
78      'pretty_version' => '2.0.31',
79      'version' => '2.0.31.0',
80      'aliases' =>
81      array (
82      ),
83      'reference' => '233a920cb38636a43b18d428f9a8db1f0a1a08f4',
84    ),
85    'simplepie/simplepie' =>
86    array (
87      'pretty_version' => '1.5.6',
88      'version' => '1.5.6.0',
89      'aliases' =>
90      array (
91      ),
92      'reference' => '1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6',
93    ),
94    'splitbrain/dokuwiki' =>
95    array (
96      'pretty_version' => 'dev-master',
97      'version' => 'dev-master',
98      'aliases' =>
99      array (
100      ),
101      'reference' => '4ee6ddae660f9ec72c1f6e2ddb72d6b29d6d8900',
102    ),
103    'splitbrain/php-archive' =>
104    array (
105      'pretty_version' => '1.2.1',
106      'version' => '1.2.1.0',
107      'aliases' =>
108      array (
109      ),
110      'reference' => '211a2198b73b233d7d2b6159462e11cd9a91348a',
111    ),
112    'splitbrain/php-cli' =>
113    array (
114      'pretty_version' => '1.1.8',
115      'version' => '1.1.8.0',
116      'aliases' =>
117      array (
118      ),
119      'reference' => '8c2c001b1b55d194402cf18aad2757049ac6d575',
120    ),
121    'splitbrain/slika' =>
122    array (
123      'pretty_version' => '1.0.4',
124      'version' => '1.0.4.0',
125      'aliases' =>
126      array (
127      ),
128      'reference' => 'fda87e816eb150f3608282da962788b4ad509c11',
129    ),
130  ),
131);
132private static $canGetVendors;
133private static $installedByVendor = array();
134
135
136
137
138
139
140
141public static function getInstalledPackages()
142{
143$packages = array();
144foreach (self::getInstalled() as $installed) {
145$packages[] = array_keys($installed['versions']);
146}
147
148
149if (1 === \count($packages)) {
150return $packages[0];
151}
152
153return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
154}
155
156
157
158
159
160
161
162
163
164public static function isInstalled($packageName)
165{
166foreach (self::getInstalled() as $installed) {
167if (isset($installed['versions'][$packageName])) {
168return true;
169}
170}
171
172return false;
173}
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188public static function satisfies(VersionParser $parser, $packageName, $constraint)
189{
190$constraint = $parser->parseConstraints($constraint);
191$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
192
193return $provided->matches($constraint);
194}
195
196
197
198
199
200
201
202
203
204
205public static function getVersionRanges($packageName)
206{
207foreach (self::getInstalled() as $installed) {
208if (!isset($installed['versions'][$packageName])) {
209continue;
210}
211
212$ranges = array();
213if (isset($installed['versions'][$packageName]['pretty_version'])) {
214$ranges[] = $installed['versions'][$packageName]['pretty_version'];
215}
216if (array_key_exists('aliases', $installed['versions'][$packageName])) {
217$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
218}
219if (array_key_exists('replaced', $installed['versions'][$packageName])) {
220$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
221}
222if (array_key_exists('provided', $installed['versions'][$packageName])) {
223$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
224}
225
226return implode(' || ', $ranges);
227}
228
229throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
230}
231
232
233
234
235
236public static function getVersion($packageName)
237{
238foreach (self::getInstalled() as $installed) {
239if (!isset($installed['versions'][$packageName])) {
240continue;
241}
242
243if (!isset($installed['versions'][$packageName]['version'])) {
244return null;
245}
246
247return $installed['versions'][$packageName]['version'];
248}
249
250throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
251}
252
253
254
255
256
257public static function getPrettyVersion($packageName)
258{
259foreach (self::getInstalled() as $installed) {
260if (!isset($installed['versions'][$packageName])) {
261continue;
262}
263
264if (!isset($installed['versions'][$packageName]['pretty_version'])) {
265return null;
266}
267
268return $installed['versions'][$packageName]['pretty_version'];
269}
270
271throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
272}
273
274
275
276
277
278public static function getReference($packageName)
279{
280foreach (self::getInstalled() as $installed) {
281if (!isset($installed['versions'][$packageName])) {
282continue;
283}
284
285if (!isset($installed['versions'][$packageName]['reference'])) {
286return null;
287}
288
289return $installed['versions'][$packageName]['reference'];
290}
291
292throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
293}
294
295
296
297
298
299public static function getRootPackage()
300{
301$installed = self::getInstalled();
302
303return $installed[0]['root'];
304}
305
306
307
308
309
310
311
312public static function getRawData()
313{
314return self::$installed;
315}
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335public static function reload($data)
336{
337self::$installed = $data;
338self::$installedByVendor = array();
339}
340
341
342
343
344private static function getInstalled()
345{
346if (null === self::$canGetVendors) {
347self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
348}
349
350$installed = array();
351
352if (self::$canGetVendors) {
353foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
354if (isset(self::$installedByVendor[$vendorDir])) {
355$installed[] = self::$installedByVendor[$vendorDir];
356} elseif (is_file($vendorDir.'/composer/installed.php')) {
357$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
358}
359}
360}
361
362$installed[] = self::$installed;
363
364return $installed;
365}
366}
367