Subversion Repositories oidplus

Rev

Rev 861 | Rev 922 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 861 Rev 874
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
 
4
 * This file is part of Composer.
-
 
5
 *
4
 
6
 * (c) Nils Adermann <naderman@naderman.de>
-
 
7
 *     Jordi Boggiano <j.boggiano@seld.be>
-
 
8
 *
5
 
9
 * For the full copyright and license information, please view the LICENSE
-
 
10
 * file that was distributed with this source code.
-
 
-
 
6
 
-
 
7
 
-
 
8
 
-
 
9
 
-
 
10
 
11
 */
11
 
12
 
12
 
13
namespace Composer;
13
namespace Composer;
14
 
14
 
15
use Composer\Autoload\ClassLoader;
15
use Composer\Autoload\ClassLoader;
16
use Composer\Semver\VersionParser;
16
use Composer\Semver\VersionParser;
17
 
17
 
18
/**
18
 
19
 * This class is copied in every Composer installed project and available to all
-
 
20
 *
19
 
21
 * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
-
 
22
 *
20
 
23
 * To require its presence, you can require `composer-runtime-api ^2.0`
-
 
-
 
21
 
-
 
22
 
24
 */
23
 
-
 
24
 
25
class InstalledVersions
25
class InstalledVersions
26
{
26
{
-
 
27
private static $installed = array (
-
 
28
  'root' =>
-
 
29
  array (
-
 
30
    'pretty_version' => '2.0',
-
 
31
    'version' => '2.0.0.0',
-
 
32
    'aliases' =>
-
 
33
    array (
-
 
34
    ),
-
 
35
    'reference' => NULL,
-
 
36
    'name' => 'danielmarschall/oidplus',
-
 
37
  ),
-
 
38
  'versions' =>
-
 
39
  array (
-
 
40
    'components/jquery' =>
-
 
41
    array (
-
 
42
      'pretty_version' => '3.6.0',
-
 
43
      'version' => '3.6.0.0',
-
 
44
      'aliases' =>
-
 
45
      array (
-
 
46
      ),
-
 
47
      'reference' => '6cf38ee1fd04b6adf8e7dda161283aa35be818c3',
-
 
48
    ),
-
 
49
    'components/jqueryui' =>
-
 
50
    array (
-
 
51
      'pretty_version' => '1.12.1',
-
 
52
      'version' => '1.12.1.0',
-
 
53
      'aliases' =>
-
 
54
      array (
-
 
55
      ),
-
 
56
      'reference' => '44ecf3794cc56b65954cc19737234a3119d036cc',
-
 
57
    ),
-
 
58
    'danielmarschall/fileformats' =>
-
 
59
    array (
-
 
60
      'pretty_version' => 'dev-master',
-
 
61
      'version' => 'dev-master',
-
 
62
      'aliases' =>
-
 
63
      array (
-
 
64
        0 => '9999999-dev',
-
 
65
      ),
-
 
66
      'reference' => '880e97b497710dc14ee8f38b4e48250ce49202ee',
-
 
67
    ),
-
 
68
    'danielmarschall/oidplus' =>
-
 
69
    array (
-
 
70
      'pretty_version' => '2.0',
-
 
71
      'version' => '2.0.0.0',
-
 
72
      'aliases' =>
-
 
73
      array (
-
 
74
      ),
-
 
75
      'reference' => NULL,
-
 
76
    ),
-
 
77
    'danielmarschall/php_utils' =>
-
 
78
    array (
-
 
79
      'pretty_version' => 'dev-master',
-
 
80
      'version' => 'dev-master',
-
 
81
      'aliases' =>
-
 
82
      array (
-
 
83
        0 => '9999999-dev',
-
 
84
      ),
-
 
85
      'reference' => '4c69eb6d92b84db5853ffd3ca3c72200094d3372',
-
 
86
    ),
-
 
87
    'danielmarschall/uuid_mac_utils' =>
-
 
88
    array (
-
 
89
      'pretty_version' => 'dev-master',
-
 
90
      'version' => 'dev-master',
-
 
91
      'aliases' =>
-
 
92
      array (
-
 
93
        0 => '9999999-dev',
-
 
94
      ),
-
 
95
      'reference' => '31174ea5dc3398645f70bc40f5162aa5b73f5b52',
-
 
96
    ),
-
 
97
    'danielmarschall/vnag' =>
-
 
98
    array (
-
 
99
      'pretty_version' => 'dev-master',
-
 
100
      'version' => 'dev-master',
-
 
101
      'aliases' =>
-
 
102
      array (
-
 
103
        0 => '9999999-dev',
-
 
104
      ),
-
 
105
      'reference' => '469bc0e8c7a9082c24bbdb59462d94da0ba2527c',
-
 
106
    ),
-
 
107
    'dcodeio/bcrypt.js' =>
-
 
108
    array (
-
 
109
      'pretty_version' => 'master',
-
 
110
      'version' => 'dev-master',
-
 
111
      'aliases' =>
-
 
112
      array (
-
 
113
      ),
-
 
114
      'reference' => 'master',
-
 
115
    ),
-
 
116
    'emn178/js-sha3' =>
-
 
117
    array (
-
 
118
      'pretty_version' => 'master',
-
 
119
      'version' => 'dev-master',
-
 
120
      'aliases' =>
-
 
121
      array (
-
 
122
      ),
-
 
123
      'reference' => 'master',
27
    /**
124
    ),
-
 
125
    'firebase/php-jwt' =>
-
 
126
    array (
-
 
127
      'pretty_version' => 'v5.5.1',
-
 
128
      'version' => '5.5.1.0',
28
     * @var mixed[]|null
129
      'aliases' =>
-
 
130
      array (
-
 
131
      ),
29
     * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
132
      'reference' => '83b609028194aa042ea33b5af2d41a7427de80e6',
-
 
133
    ),
-
 
134
    'gedmarc/layout' =>
-
 
135
    array (
-
 
136
      'pretty_version' => 'master',
-
 
137
      'version' => 'dev-master',
-
 
138
      'aliases' =>
-
 
139
      array (
30
     */
140
      ),
-
 
141
      'reference' => 'master',
-
 
142
    ),
31
    private static $installed;
143
    'matthiasmullie/minify' =>
-
 
144
    array (
-
 
145
      'pretty_version' => '1.3.68',
-
 
146
      'version' => '1.3.68.0',
-
 
147
      'aliases' =>
-
 
148
      array (
-
 
149
      ),
-
 
150
      'reference' => 'c00fb02f71b2ef0a5f53fe18c5a8b9aa30f48297',
32
 
151
    ),
-
 
152
    'matthiasmullie/path-converter' =>
-
 
153
    array (
-
 
154
      'pretty_version' => '1.1.3',
-
 
155
      'version' => '1.1.3.0',
-
 
156
      'aliases' =>
-
 
157
      array (
-
 
158
      ),
-
 
159
      'reference' => 'e7d13b2c7e2f2268e1424aaed02085518afa02d9',
-
 
160
    ),
-
 
161
    'n-other/php-sha3' =>
-
 
162
    array (
-
 
163
      'pretty_version' => 'dev-master',
-
 
164
      'version' => 'dev-master',
-
 
165
      'aliases' =>
-
 
166
      array (
-
 
167
        0 => '9999999-dev',
-
 
168
      ),
-
 
169
      'reference' => '54ee3b90986e88286d333319e6340b90bde4f71a',
-
 
170
    ),
-
 
171
    'paragonie/constant_time_encoding' =>
-
 
172
    array (
-
 
173
      'pretty_version' => 'v2.6.3',
-
 
174
      'version' => '2.6.3.0',
-
 
175
      'aliases' =>
-
 
176
      array (
-
 
177
      ),
-
 
178
      'reference' => '58c3f47f650c94ec05a151692652a868995d2938',
-
 
179
    ),
-
 
180
    'paragonie/random_compat' =>
-
 
181
    array (
-
 
182
      'pretty_version' => 'v9.99.100',
-
 
183
      'version' => '9.99.100.0',
-
 
184
      'aliases' =>
-
 
185
      array (
-
 
186
      ),
-
 
187
      'reference' => '996434e5492cb4c3edcb9168db6fbb1359ef965a',
-
 
188
    ),
-
 
189
    'phpseclib/phpseclib' =>
-
 
190
    array (
-
 
191
      'pretty_version' => '3.0.14',
-
 
192
      'version' => '3.0.14.0',
-
 
193
      'aliases' =>
-
 
194
      array (
-
 
195
      ),
-
 
196
      'reference' => '2f0b7af658cbea265cbb4a791d6c29a6613f98ef',
-
 
197
    ),
-
 
198
    'script47/bs5-utils' =>
-
 
199
    array (
-
 
200
      'pretty_version' => 'master',
-
 
201
      'version' => 'dev-master',
-
 
202
      'aliases' =>
-
 
203
      array (
-
 
204
      ),
-
 
205
      'reference' => 'master',
-
 
206
    ),
-
 
207
    'spamspan/spamspan' =>
-
 
208
    array (
-
 
209
      'pretty_version' => 'master',
-
 
210
      'version' => 'dev-master',
-
 
211
      'aliases' =>
-
 
212
      array (
-
 
213
      ),
-
 
214
      'reference' => 'master',
-
 
215
    ),
-
 
216
    'symfony/polyfill-mbstring' =>
-
 
217
    array (
-
 
218
      'pretty_version' => 'v1.19.0',
-
 
219
      'version' => '1.19.0.0',
-
 
220
      'aliases' =>
-
 
221
      array (
-
 
222
      ),
-
 
223
      'reference' => 'b5f7b932ee6fa802fc792eabd77c4c88084517ce',
-
 
224
    ),
-
 
225
    'tinymce/tinymce' =>
-
 
226
    array (
-
 
227
      'pretty_version' => '5.x-dev',
-
 
228
      'version' => '5.9999999.9999999.9999999-dev',
-
 
229
      'aliases' =>
-
 
230
      array (
-
 
231
      ),
-
 
232
      'reference' => 'c91227ab933d664c3ce2ea4ec68257f2282437ed',
-
 
233
    ),
-
 
234
    'twbs/bootstrap' =>
-
 
235
    array (
-
 
236
      'pretty_version' => 'v5.2.0-beta1',
-
 
237
      'version' => '5.2.0.0-beta1',
-
 
238
      'aliases' =>
-
 
239
      array (
-
 
240
      ),
-
 
241
      'reference' => 'fca04c07131a81e625a516cf7b98a8c7df0df1c1',
-
 
242
    ),
-
 
243
    'tweeb/tinymce-i18n' =>
-
 
244
    array (
-
 
245
      'pretty_version' => '2.0.4',
-
 
246
      'version' => '2.0.4.0',
-
 
247
      'aliases' =>
-
 
248
      array (
-
 
249
      ),
-
 
250
      'reference' => '058da08d6e61dc4e0279de6509bb6969a62f68e5',
-
 
251
    ),
-
 
252
    'twitter/bootstrap' =>
-
 
253
    array (
-
 
254
      'replaced' =>
-
 
255
      array (
-
 
256
        0 => 'v5.2.0-beta1',
-
 
257
      ),
33
    /**
258
    ),
-
 
259
    'vakata/jstree' =>
-
 
260
    array (
-
 
261
      'pretty_version' => '3.3.12',
-
 
262
      'version' => '3.3.12.0',
34
     * @var bool|null
263
      'aliases' =>
-
 
264
      array (
35
     */
265
      ),
-
 
266
      'reference' => '7a03954015eaea2467956dc05e6be78f4d1a1ff0',
-
 
267
    ),
-
 
268
  ),
-
 
269
);
36
    private static $canGetVendors;
270
private static $canGetVendors;
37
 
-
 
38
    /**
-
 
39
     * @var array[]
-
 
40
     * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
-
 
41
     */
-
 
42
    private static $installedByVendor = array();
271
private static $installedByVendor = array();
43
 
272
 
44
    /**
273
 
45
     * Returns a list of all package names which are present, either by being installed, replaced or provided
-
 
46
     *
274
 
47
     * @return string[]
-
 
48
     * @psalm-return list<string>
-
 
-
 
275
 
-
 
276
 
-
 
277
 
49
     */
278
 
50
    public static function getInstalledPackages()
279
public static function getInstalledPackages()
51
    {
280
{
52
        $packages = array();
281
$packages = array();
53
        foreach (self::getInstalled() as $installed) {
282
foreach (self::getInstalled() as $installed) {
54
            $packages[] = array_keys($installed['versions']);
283
$packages[] = array_keys($installed['versions']);
Line 59... Line 288...
59
        }
288
}
60
 
289
 
61
        return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
290
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
62
    }
291
}
63
 
292
 
64
    /**
-
 
65
     * Returns a list of all package names with a specific type e.g. 'library'
-
 
66
     *
-
 
67
     * @param  string   $type
-
 
68
     * @return string[]
-
 
69
     * @psalm-return list<string>
-
 
70
     */
-
 
71
    public static function getInstalledPackagesByType($type)
-
 
72
    {
-
 
73
        $packagesByType = array();
-
 
74
 
293
 
75
        foreach (self::getInstalled() as $installed) {
-
 
76
            foreach ($installed['versions'] as $name => $package) {
-
 
77
                if (isset($package['type']) && $package['type'] === $type) {
-
 
78
                    $packagesByType[] = $name;
-
 
79
                }
-
 
80
            }
-
 
81
        }
-
 
82
 
294
 
83
        return $packagesByType;
-
 
84
    }
-
 
85
 
295
 
86
    /**
296
 
87
     * Checks whether the given package is installed
-
 
88
     *
297
 
89
     * This also returns true if the package name is provided or replaced by another package
-
 
90
     *
298
 
91
     * @param  string $packageName
-
 
92
     * @param  bool   $includeDevRequirements
-
 
93
     * @return bool
-
 
-
 
299
 
94
     */
300
 
95
    public static function isInstalled($packageName, $includeDevRequirements = true)
301
public static function isInstalled($packageName)
96
    {
302
{
97
        foreach (self::getInstalled() as $installed) {
303
foreach (self::getInstalled() as $installed) {
98
            if (isset($installed['versions'][$packageName])) {
304
if (isset($installed['versions'][$packageName])) {
99
                return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
305
return true;
100
            }
306
}
101
        }
307
}
102
 
308
 
103
        return false;
309
return false;
104
    }
310
}
105
 
311
 
106
    /**
312
 
107
     * Checks whether the given package satisfies a version constraint
-
 
108
     *
313
 
109
     * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
-
 
110
     *
314
 
111
     *   Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
-
 
112
     *
315
 
113
     * @param  VersionParser $parser      Install composer/semver to have access to this class and functionality
-
 
114
     * @param  string        $packageName
-
 
115
     * @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
-
 
116
     * @return bool
-
 
-
 
316
 
-
 
317
 
-
 
318
 
-
 
319
 
-
 
320
 
-
 
321
 
-
 
322
 
-
 
323
 
117
     */
324
 
118
    public static function satisfies(VersionParser $parser, $packageName, $constraint)
325
public static function satisfies(VersionParser $parser, $packageName, $constraint)
119
    {
326
{
120
        $constraint = $parser->parseConstraints($constraint);
327
$constraint = $parser->parseConstraints($constraint);
121
        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
328
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
122
 
329
 
123
        return $provided->matches($constraint);
330
return $provided->matches($constraint);
124
    }
331
}
125
 
332
 
126
    /**
333
 
127
     * Returns a version constraint representing all the range(s) which are installed for a given package
-
 
128
     *
334
 
129
     * It is easier to use this via isInstalled() with the $constraint argument if you need to check
-
 
130
     * whether a given version of a package is installed, and not just whether it exists
-
 
131
     *
335
 
132
     * @param  string $packageName
-
 
133
     * @return string Version constraint usable with composer/semver
-
 
-
 
336
 
-
 
337
 
-
 
338
 
-
 
339
 
-
 
340
 
134
     */
341
 
135
    public static function getVersionRanges($packageName)
342
public static function getVersionRanges($packageName)
136
    {
343
{
137
        foreach (self::getInstalled() as $installed) {
344
foreach (self::getInstalled() as $installed) {
138
            if (!isset($installed['versions'][$packageName])) {
345
if (!isset($installed['versions'][$packageName])) {
139
                continue;
346
continue;
Line 157... Line 364...
157
        }
364
}
158
 
365
 
159
        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
366
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
160
    }
367
}
161
 
368
 
-
 
369
 
-
 
370
 
162
    /**
371
 
163
     * @param  string      $packageName
-
 
164
     * @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
-
 
165
     */
372
 
166
    public static function getVersion($packageName)
373
public static function getVersion($packageName)
167
    {
374
{
168
        foreach (self::getInstalled() as $installed) {
375
foreach (self::getInstalled() as $installed) {
169
            if (!isset($installed['versions'][$packageName])) {
376
if (!isset($installed['versions'][$packageName])) {
170
                continue;
377
continue;
Line 178... Line 385...
178
        }
385
}
179
 
386
 
180
        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
387
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
181
    }
388
}
182
 
389
 
-
 
390
 
-
 
391
 
183
    /**
392
 
184
     * @param  string      $packageName
-
 
185
     * @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
-
 
186
     */
393
 
187
    public static function getPrettyVersion($packageName)
394
public static function getPrettyVersion($packageName)
188
    {
395
{
189
        foreach (self::getInstalled() as $installed) {
396
foreach (self::getInstalled() as $installed) {
190
            if (!isset($installed['versions'][$packageName])) {
397
if (!isset($installed['versions'][$packageName])) {
191
                continue;
398
continue;
Line 199... Line 406...
199
        }
406
}
200
 
407
 
201
        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
408
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
202
    }
409
}
203
 
410
 
-
 
411
 
-
 
412
 
204
    /**
413
 
205
     * @param  string      $packageName
-
 
206
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
-
 
207
     */
414
 
208
    public static function getReference($packageName)
415
public static function getReference($packageName)
209
    {
416
{
210
        foreach (self::getInstalled() as $installed) {
417
foreach (self::getInstalled() as $installed) {
211
            if (!isset($installed['versions'][$packageName])) {
418
if (!isset($installed['versions'][$packageName])) {
212
                continue;
419
continue;
Line 220... Line 427...
220
        }
427
}
221
 
428
 
222
        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
429
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
223
    }
430
}
224
 
431
 
225
    /**
-
 
226
     * @param  string      $packageName
-
 
227
     * @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.
-
 
228
     */
-
 
229
    public static function getInstallPath($packageName)
-
 
230
    {
-
 
231
        foreach (self::getInstalled() as $installed) {
-
 
232
            if (!isset($installed['versions'][$packageName])) {
-
 
233
                continue;
-
 
234
            }
-
 
235
 
432
 
236
            return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
-
 
237
        }
-
 
238
 
433
 
239
        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
-
 
240
    }
-
 
241
 
434
 
242
    /**
-
 
243
     * @return array
-
 
244
     * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
-
 
245
     */
435
 
246
    public static function getRootPackage()
436
public static function getRootPackage()
247
    {
437
{
248
        $installed = self::getInstalled();
438
$installed = self::getInstalled();
249
 
439
 
250
        return $installed[0]['root'];
440
return $installed[0]['root'];
251
    }
441
}
252
 
442
 
253
    /**
443
 
254
     * Returns the raw installed.php data for custom implementations
-
 
255
     *
444
 
256
     * @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.
-
 
257
     * @return array[]
-
 
-
 
445
 
-
 
446
 
-
 
447
 
258
     * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
448
 
259
     */
449
 
260
    public static function getRawData()
450
public static function getRawData()
261
    {
451
{
262
        @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);
452
@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);
263
 
453
 
264
        if (null === self::$installed) {
-
 
265
            // only require the installed.php file if this file is loaded from its dumped location,
-
 
266
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
-
 
267
            if (substr(__DIR__, -8, 1) !== 'C') {
-
 
268
                self::$installed = include __DIR__ . '/installed.php';
-
 
269
            } else {
-
 
270
                self::$installed = array();
-
 
271
            }
-
 
272
        }
-
 
273
 
-
 
274
        return self::$installed;
454
return self::$installed;
275
    }
455
}
276
 
456
 
277
    /**
457
 
278
     * Returns the raw data of all installed.php which are currently loaded for custom implementations
-
 
279
     *
458
 
280
     * @return array[]
-
 
-
 
459
 
-
 
460
 
281
     * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
461
 
282
     */
462
 
283
    public static function getAllRawData()
463
public static function getAllRawData()
284
    {
464
{
285
        return self::getInstalled();
465
return self::getInstalled();
286
    }
466
}
287
 
467
 
288
    /**
468
 
289
     * Lets you reload the static array from another file
-
 
290
     *
469
 
291
     * This is only useful for complex integrations in which a project needs to use
-
 
292
     * this class but then also needs to execute another project's autoloader in process,
-
 
293
     * and wants to ensure both projects have access to their version of installed.php.
-
 
294
     *
470
 
295
     * A typical case would be PHPUnit, where it would need to make sure it reads all
-
 
296
     * the data it needs from this class, then call reload() with
-
 
297
     * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
-
 
298
     * the project in which it runs can then also use this class safely, without
-
 
299
     * interference between PHPUnit's dependencies and the project's dependencies.
-
 
300
     *
471
 
301
     * @param  array[] $data A vendor/composer/installed.php data set
-
 
302
     * @return void
-
 
-
 
472
 
-
 
473
 
-
 
474
 
-
 
475
 
-
 
476
 
-
 
477
 
-
 
478
 
-
 
479
 
-
 
480
 
-
 
481
 
-
 
482
 
303
     *
483
 
304
     * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
484
 
305
     */
485
 
306
    public static function reload($data)
486
public static function reload($data)
307
    {
487
{
308
        self::$installed = $data;
488
self::$installed = $data;
309
        self::$installedByVendor = array();
489
self::$installedByVendor = array();
310
    }
490
}
311
 
491
 
312
    /**
492
 
313
     * @return array[]
-
 
-
 
493
 
314
     * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
494
 
315
     */
495
 
316
    private static function getInstalled()
496
private static function getInstalled()
317
    {
497
{
318
        if (null === self::$canGetVendors) {
498
if (null === self::$canGetVendors) {
319
            self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
499
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
320
        }
500
}
Line 325... Line 505...
325
            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
505
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
326
                if (isset(self::$installedByVendor[$vendorDir])) {
506
if (isset(self::$installedByVendor[$vendorDir])) {
327
                    $installed[] = self::$installedByVendor[$vendorDir];
507
$installed[] = self::$installedByVendor[$vendorDir];
328
                } elseif (is_file($vendorDir.'/composer/installed.php')) {
508
} elseif (is_file($vendorDir.'/composer/installed.php')) {
329
                    $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
509
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
330
                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
-
 
331
                        self::$installed = $installed[count($installed) - 1];
-
 
332
                    }
-
 
333
                }
510
}
334
            }
511
}
335
        }
512
}
336
 
513
 
337
        if (null === self::$installed) {
-
 
338
            // only require the installed.php file if this file is loaded from its dumped location,
-
 
339
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
-
 
340
            if (substr(__DIR__, -8, 1) !== 'C') {
-
 
341
                self::$installed = require __DIR__ . '/installed.php';
-
 
342
            } else {
-
 
343
                self::$installed = array();
-
 
344
            }
-
 
345
        }
-
 
346
        $installed[] = self::$installed;
514
$installed[] = self::$installed;
347
 
515
 
348
        return $installed;
516
return $installed;
349
    }
517
}
350
}
518
}