Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ApieCommonPlugin | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
| activate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deactivate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| uninstall | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSubscribedEvents | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| generatePhpCode | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | namespace Apie\ApieCommonPlugin; |
| 3 | |
| 4 | use Composer\Composer; |
| 5 | use Composer\EventDispatcher\EventSubscriberInterface; |
| 6 | use Composer\IO\IOInterface; |
| 7 | use Composer\Plugin\PluginInterface; |
| 8 | |
| 9 | class ApieCommonPlugin implements PluginInterface, EventSubscriberInterface |
| 10 | { |
| 11 | protected Composer $composer; |
| 12 | |
| 13 | public function activate(Composer $composer, IOInterface $io): void |
| 14 | { |
| 15 | $this->composer = $composer; |
| 16 | } |
| 17 | |
| 18 | public function deactivate(Composer $composer, IOInterface $io): void |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | public function uninstall(Composer $composer, IOInterface $io): void |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | public static function getSubscribedEvents(): array |
| 27 | { |
| 28 | return [ |
| 29 | 'post-install-cmd' => 'generatePhpCode', |
| 30 | 'post-update-cmd' => 'generatePhpCode', |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | public function generatePhpCode(): void |
| 35 | { |
| 36 | $installedRepo = $this->composer->getRepositoryManager()->getLocalRepository(); |
| 37 | $packages = $installedRepo->getPackages(); |
| 38 | |
| 39 | $classNames = []; |
| 40 | foreach ($packages as $package) { |
| 41 | $extra = $package->getExtra(); |
| 42 | if (isset($extra['apie-objects']) && is_array($extra['apie-objects'])) { |
| 43 | $classNames = [...$classNames, ...$extra['apie-objects']]; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | $generator = new AvailableApieObjectProviderGenerator(); |
| 48 | $generator->generateFile($classNames); |
| 49 | @chmod(__DIR__ . '/AvailableApieObjectProvider.php', 0666); |
| 50 | } |
| 51 | } |