1 | <?php |
||
13 | final class FallbackVersions |
||
14 | { |
||
15 | const ROOT_PACKAGE_NAME = 'unknown/root-package@UNKNOWN'; |
||
16 | |||
17 | private function __construct() |
||
20 | |||
21 | /** |
||
22 | * @param string $packageName |
||
23 | * |
||
24 | * @return string |
||
25 | * |
||
26 | * @throws \OutOfBoundsException if a version cannot be located |
||
27 | * @throws \UnexpectedValueException if the composer.lock file could not be located |
||
28 | */ |
||
29 | 3 | public static function getVersion(string $packageName) : string |
|
30 | { |
||
31 | 3 | $versions = iterator_to_array(self::getVersions(self::getComposerLockPath())); |
|
32 | |||
33 | 2 | if (! array_key_exists($packageName, $versions)) { |
|
34 | 1 | throw new \OutOfBoundsException( |
|
35 | 1 | 'Required package "' . $packageName . '" is not installed: cannot detect its version' |
|
36 | ); |
||
37 | } |
||
38 | |||
39 | 1 | return $versions[$packageName]; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | * |
||
45 | * @throws \UnexpectedValueException |
||
46 | */ |
||
47 | 3 | private static function getComposerLockPath() : string |
|
65 | |||
66 | 2 | private static function getVersions(string $composerLockFile) : \Generator |
|
80 | } |
||
81 |