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