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) |
||
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | 1 | public static function getSubscribedEvents() |
|
74 | |||
75 | /** |
||
76 | * @param Event $composerEvent |
||
77 | * |
||
78 | * @return void |
||
79 | * |
||
80 | * @throws \RuntimeException |
||
81 | */ |
||
82 | 13 | public static function dumpVersionsClass(Event $composerEvent) |
|
98 | |||
99 | 12 | private static function generateVersionsClass(string $rootPackageName, array $versions) : string |
|
108 | |||
109 | /** |
||
110 | * @param string $versionClassSource |
||
111 | * @param Composer $composer |
||
112 | * @param IOInterface $io |
||
113 | * |
||
114 | * @return void |
||
115 | * |
||
116 | * @throws \RuntimeException |
||
117 | */ |
||
118 | 12 | private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io) |
|
136 | |||
137 | /** |
||
138 | * @param Config $composerConfig |
||
139 | * @param RootPackageInterface $rootPackage |
||
140 | * |
||
141 | * @return string |
||
142 | * |
||
143 | * @throws \RuntimeException |
||
144 | */ |
||
145 | 12 | private static function locateRootPackageInstallPath( |
|
155 | |||
156 | 12 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) : PackageInterface |
|
166 | |||
167 | /** |
||
168 | * @param Locker $locker |
||
169 | * @param RootPackageInterface $rootPackage |
||
170 | * |
||
171 | * @return \Generator|\string[] |
||
172 | */ |
||
173 | 13 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) : \Generator |
|
187 | } |
||
188 |