1 | <?php |
||
17 | final class Installer implements PluginInterface, EventSubscriberInterface |
||
18 | { |
||
19 | private static $generatedClassTemplate = <<<'PHP' |
||
20 | <?php |
||
21 | |||
22 | namespace PackageVersions; |
||
23 | |||
24 | /** |
||
25 | * This class is generated by ocramius/package-versions, specifically by |
||
26 | * @see \PackageVersions\Installer |
||
27 | * |
||
28 | * This file is overwritten at every run of `composer install` or `composer update`. |
||
29 | */ |
||
30 | %s |
||
31 | { |
||
32 | const ROOT_PACKAGE_NAME = '%s'; |
||
33 | const VERSIONS = %s; |
||
34 | |||
35 | private function __construct() |
||
36 | { |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @throws \OutOfBoundsException if a version cannot be located |
||
41 | */ |
||
42 | public static function getVersion(string $packageName) : string |
||
43 | { |
||
44 | if (isset(self::VERSIONS[$packageName])) { |
||
45 | return self::VERSIONS[$packageName]; |
||
46 | } |
||
47 | |||
48 | throw new \OutOfBoundsException( |
||
49 | 'Required package "' . $packageName . '" is not installed: cannot detect its version' |
||
50 | ); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | PHP; |
||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | public function activate(Composer $composer, IOInterface $io) : void |
||
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | 1 | public static function getSubscribedEvents() : array |
|
74 | |||
75 | /** |
||
76 | * @throws \RuntimeException |
||
77 | */ |
||
78 | 13 | public static function dumpVersionsClass(Event $composerEvent) : void |
|
94 | |||
95 | 12 | private static function generateVersionsClass(string $rootPackageName, array $versions) : string |
|
104 | |||
105 | /** |
||
106 | * @throws \RuntimeException |
||
107 | */ |
||
108 | 12 | private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io) : void |
|
126 | |||
127 | /** |
||
128 | * @throws \RuntimeException |
||
129 | */ |
||
130 | 12 | private static function locateRootPackageInstallPath( |
|
140 | |||
141 | 12 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) : PackageInterface |
|
151 | |||
152 | /** |
||
153 | * @return \Generator|\string[] |
||
154 | */ |
||
155 | 13 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) : \Generator |
|
178 | } |
||
179 |