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 | * @throws \OutOfBoundsException if a version cannot be located |
||
56 | */ |
||
57 | public static function getShortVersion($packageName) |
||
58 | { |
||
59 | return explode('@', static::getVersion($packageName))[0]; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @throws \OutOfBoundsException if a version cannot be located |
||
64 | */ |
||
65 | public static function getMajorVersion($packageName) |
||
66 | { |
||
67 | return explode('.', static::getShortVersion($packageName))[0]; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | PHP; |
||
72 | |||
73 | /** |
||
74 | * {@inheritDoc} |
||
75 | */ |
||
76 | 1 | public function activate(Composer $composer, IOInterface $io) |
|
80 | |||
81 | /** |
||
82 | * {@inheritDoc} |
||
83 | */ |
||
84 | 1 | public static function getSubscribedEvents() |
|
91 | |||
92 | /** |
||
93 | * @param Event $composerEvent |
||
94 | * |
||
95 | * @return void |
||
96 | * |
||
97 | * @throws \RuntimeException |
||
98 | */ |
||
99 | 9 | public static function dumpVersionsClass(Event $composerEvent) |
|
115 | |||
116 | 9 | private static function generateVersionsClass(Composer $composer) |
|
124 | |||
125 | /** |
||
126 | * @param string $versionClassSource |
||
127 | * @param Config $composerConfig |
||
128 | * @param RootPackageInterface $rootPackage |
||
129 | * |
||
130 | * @return void |
||
131 | * |
||
132 | * @throws \RuntimeException |
||
133 | */ |
||
134 | 9 | private static function writeVersionClassToFile( |
|
146 | |||
147 | /** |
||
148 | * @param Config $composerConfig |
||
149 | * @param RootPackageInterface $rootPackage |
||
150 | * |
||
151 | * @return string |
||
152 | * |
||
153 | * @throws \RuntimeException |
||
154 | */ |
||
155 | 9 | private static function locateRootPackageInstallPath( |
|
165 | |||
166 | 9 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) |
|
176 | |||
177 | /** |
||
178 | * @param Locker $locker |
||
179 | * @param RootPackageInterface $rootPackage |
||
180 | * |
||
181 | * @return \Generator|\string[] |
||
182 | */ |
||
183 | 9 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) |
|
199 | } |
||
200 |