1 | <?php |
||
32 | final class Installer implements PluginInterface, EventSubscriberInterface |
||
33 | { |
||
34 | /** @var string */ |
||
35 | private static $generatedClassTemplate = <<<'PHP' |
||
36 | <?php |
||
37 | |||
38 | declare(strict_types=1); |
||
39 | |||
40 | namespace PackageVersions; |
||
41 | |||
42 | /** |
||
43 | * This class is generated by ocramius/package-versions, specifically by |
||
44 | * @see \PackageVersions\Installer |
||
45 | * |
||
46 | * This file is overwritten at every run of `composer install` or `composer update`. |
||
47 | */ |
||
48 | %s |
||
49 | { |
||
50 | public const ROOT_PACKAGE_NAME = '%s'; |
||
51 | /** |
||
52 | * Array of all available composer packages. |
||
53 | * Dont read this array from your calling code, but use the \PackageVersions\Versions::getVersion() method instead. |
||
54 | * |
||
55 | * @var array<string, string> |
||
56 | * @internal |
||
57 | */ |
||
58 | public const VERSIONS = %s; |
||
59 | |||
60 | private function __construct() |
||
61 | { |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @throws \OutOfBoundsException If a version cannot be located. |
||
66 | * |
||
67 | * @psalm-param key-of<self::VERSIONS> $packageName |
||
68 | */ |
||
69 | public static function getVersion(string $packageName) : string |
||
70 | { |
||
71 | if (isset(self::VERSIONS[$packageName])) { |
||
72 | return self::VERSIONS[$packageName]; |
||
73 | } |
||
74 | |||
75 | throw new \OutOfBoundsException( |
||
76 | 'Required package "' . $packageName . '" is not installed: cannot detect its version' |
||
77 | ); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | PHP; |
||
82 | |||
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | public function activate(Composer $composer, IOInterface $io) : void |
||
90 | |||
91 | /** |
||
92 | * {@inheritDoc} |
||
93 | */ |
||
94 | 1 | public static function getSubscribedEvents() : array |
|
102 | |||
103 | /** |
||
104 | * @throws RuntimeException |
||
105 | */ |
||
106 | 14 | public static function dumpVersionsClass(Event $composerEvent) : void |
|
122 | |||
123 | /** |
||
124 | * @param string[] $versions |
||
125 | */ |
||
126 | 13 | private static function generateVersionsClass(string $rootPackageName, array $versions) : string |
|
135 | |||
136 | /** |
||
137 | * @throws RuntimeException |
||
138 | */ |
||
139 | 13 | private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io) : void |
|
159 | |||
160 | /** |
||
161 | * @throws RuntimeException |
||
162 | */ |
||
163 | 13 | private static function locateRootPackageInstallPath( |
|
173 | |||
174 | 13 | private static function getRootPackageAlias(RootPackageInterface $rootPackage) : PackageInterface |
|
184 | |||
185 | /** |
||
186 | * @return Generator|string[] |
||
187 | */ |
||
188 | 14 | private static function getVersions(Locker $locker, RootPackageInterface $rootPackage) : Generator |
|
211 | } |
||
212 |