| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Composer; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class ComposerJson { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
private $contents; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function __construct( $location ) { |
| 21 |
$this->contents = json_decode( file_get_contents( $location ), true ); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function getRequiredDependencies() { |
| 30 |
$deps = []; |
| 31 |
if ( isset( $this->contents['require'] ) ) { |
| 32 |
foreach ( $this->contents['require'] as $package => $version ) { |
| 33 |
|
| 34 |
|
| 35 |
if ( strpos( $package, '/' ) !== false ) { |
| 36 |
$deps[$package] = self::normalizeVersion( $version ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return $deps; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public static function normalizeVersion( $version ) { |
| 51 |
|
| 52 |
return ltrim( $version, 'v' ); |
| 53 |
} |
| 54 |
|
| 55 |
} |