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 VERSIONS = %s; |
||
33 | |||
34 | private function __construct() |
||
35 | { |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @throws \OutOfBoundsException if a version cannot be located |
||
40 | */ |
||
41 | public static function getVersion(string $packageName) : string |
||
42 | { |
||
43 | if (! isset(self::VERSIONS[$packageName])) { |
||
44 | throw new \OutOfBoundsException( |
||
45 | 'Required package "' . $packageName . '" is not installed: cannot detect its version' |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | return self::VERSIONS[$packageName]; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | PHP; |
||
54 | |||
55 | /** |
||
56 | * {@inheritDoc} |
||
57 | */ |
||
58 | public function activate(Composer $composer, IOInterface $io) |
||
59 | { |
||
60 | // Nothing to do here, as all features are provided through event listeners |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | 1 | public static function getSubscribedEvents() |
|
73 | |||
74 | /** |
||
75 | * @param Event $composerEvent |
||
76 | * |
||
77 | * @return void |
||
78 | * |
||
79 | * @throws \RuntimeException |
||
80 | */ |
||
81 | 12 | public static function dumpVersionsClass(Event $composerEvent) |
|
94 | |||
95 | 11 | private static function generateVersionsClass(array $versions) : string |
|
103 | |||
104 | /** |
||
105 | * @param string $versionClassSource |
||
106 | * @param Composer $composer |
||
107 | * @param IOInterface $io |
||
108 | * |
||
109 | * @return void |
||
110 | * |
||
111 | * @throws \RuntimeException |
||
112 | */ |
||
113 | 11 | private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io) |
|
131 | |||
132 | /** |
||
133 | * @param Config $composerConfig |
||
134 | * @param RootPackageInterface $rootPackage |
||
135 | * |
||
136 | * @return string |
||
137 | * |
||
138 | * @throws \RuntimeException |
||
139 | */ |
||
140 | 11 | private static function locateRootPackageInstallPath( |
|
150 | |||
151 | 11 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) : PackageInterface |
|
161 | |||
162 | /** |
||
163 | * @param Locker $locker |
||
164 | * @param RootPackageInterface $rootPackage |
||
165 | * |
||
166 | * @return \Generator|\string[] |
||
167 | */ |
||
168 | 12 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) : \Generator |
|
182 | } |
||
183 |