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 | $selfVersion = self::VERSIONS; |
||
44 | |||
45 | if (isset($selfVersion[$packageName])) { |
||
46 | throw new \OutOfBoundsException( |
||
47 | 'Required package "' . $packageName . '" is not installed: cannot detect its version' |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | return $selfVersion[$packageName]; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | PHP; |
||
56 | |||
57 | /** |
||
58 | * {@inheritDoc} |
||
59 | */ |
||
60 | public function activate(Composer $composer, IOInterface $io) |
||
64 | |||
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | public static function getSubscribedEvents() |
||
75 | |||
76 | /** |
||
77 | * @param Event $composerEvent |
||
78 | * |
||
79 | * @return void |
||
80 | * |
||
81 | * @throws \RuntimeException |
||
82 | */ |
||
83 | public static function dumpVersionsClass(Event $composerEvent) |
||
99 | |||
100 | private static function generateVersionsClass(Composer $composer) |
||
108 | |||
109 | /** |
||
110 | * @param string $versionClassSource |
||
111 | * @param Config $composerConfig |
||
112 | * @param RootPackageInterface $rootPackage |
||
113 | * |
||
114 | * @return void |
||
115 | * |
||
116 | * @throws \RuntimeException |
||
117 | */ |
||
118 | private static function writeVersionClassToFile( |
||
130 | |||
131 | /** |
||
132 | * @param Config $composerConfig |
||
133 | * @param RootPackageInterface $rootPackage |
||
134 | * |
||
135 | * @return string |
||
136 | * |
||
137 | * @throws \RuntimeException |
||
138 | */ |
||
139 | private static function locateRootPackageInstallPath( |
||
149 | |||
150 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) |
||
160 | |||
161 | /** |
||
162 | * @param Locker $locker |
||
163 | * @param RootPackageInterface $rootPackage |
||
164 | * |
||
165 | * @return \Generator|\string[] |
||
166 | */ |
||
167 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) |
||
183 | } |
||
184 |