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 samsonasik/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($packageName) |
||
42 | { |
||
43 | if (null !== 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) |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | public static function getSubscribedEvents() |
||
73 | |||
74 | /** |
||
75 | * @param Event $composerEvent |
||
76 | * |
||
77 | * @return void |
||
78 | * |
||
79 | * @throws \RuntimeException |
||
80 | */ |
||
81 | public static function dumpVersionsClass(Event $composerEvent) |
||
97 | |||
98 | private static function generateVersionsClass(Composer $composer) |
||
106 | |||
107 | /** |
||
108 | * @param string $versionClassSource |
||
109 | * @param Config $composerConfig |
||
110 | * @param RootPackageInterface $rootPackage |
||
111 | * |
||
112 | * @return void |
||
113 | * |
||
114 | * @throws \RuntimeException |
||
115 | */ |
||
116 | private static function writeVersionClassToFile( |
||
128 | |||
129 | /** |
||
130 | * @param Config $composerConfig |
||
131 | * @param RootPackageInterface $rootPackage |
||
132 | * |
||
133 | * @return string |
||
134 | * |
||
135 | * @throws \RuntimeException |
||
136 | */ |
||
137 | private static function locateRootPackageInstallPath( |
||
147 | |||
148 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) |
||
158 | |||
159 | /** |
||
160 | * @param Locker $locker |
||
161 | * @param RootPackageInterface $rootPackage |
||
162 | * |
||
163 | * @return \Generator|\string[] |
||
164 | */ |
||
165 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) |
||
181 | } |
||
182 |