MediaWiki
REL1_35
ComposerJson.php
Go to the documentation of this file.
1
<?php
2
9
class
ComposerJson
{
13
private
$contents
;
14
18
public
function
__construct
( $location ) {
19
$this->contents = json_decode( file_get_contents( $location ),
true
);
20
}
21
27
public
function
getRequiredDependencies
() {
28
$deps = [];
29
if
( isset( $this->contents[
'require'
] ) ) {
30
foreach
( $this->contents[
'require'
] as $package => $version ) {
31
// Examples of package dependancies that don't have a / in the name:
32
// php, ext-xml, composer-plugin-api
33
if
( strpos( $package,
'/'
) !==
false
) {
34
$deps[$package] =
self::normalizeVersion
( $version );
35
}
36
}
37
}
38
39
return
$deps;
40
}
41
48
public
static
function
normalizeVersion
( $version ) {
49
if
( strpos( $version,
'v'
) === 0 ) {
50
// Composer auto-strips the "v" in front of the tag name
51
$version = ltrim( $version,
'v'
);
52
}
53
54
return
$version;
55
}
56
57
}
ComposerJson
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Definition
ComposerJson.php:9
ComposerJson\normalizeVersion
static normalizeVersion( $version)
Strip a leading "v" from the version name.
Definition
ComposerJson.php:48
ComposerJson\getRequiredDependencies
getRequiredDependencies()
Dependencies as specified by composer.json.
Definition
ComposerJson.php:27
ComposerJson\$contents
array[] $contents
Definition
ComposerJson.php:13
ComposerJson\__construct
__construct( $location)
Definition
ComposerJson.php:18
includes
libs
composer
ComposerJson.php
Generated on Sat Apr 6 2024 00:07:21 for MediaWiki by
1.9.8