Skip to content

Commit 259329b

Browse files
committed
Also remove final classes when running composer install/update
1 parent 46bf8d4 commit 259329b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ When does this plugin update EasyAdmin classes?
2020

2121
* Just after installing this Composer plugin;
2222
* Just after installing or updating any EasyAdmin version.
23+
* Just after running `composer update` or `composer install` commands.
2324

2425
[1]: https://easycorp.github.io/blog/posts/the-road-to-easyadmin-3-no-more-inheritance

src/NoFinalClassPlugin.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Composer\IO\IOInterface;
1313
use Composer\Package\PackageInterface;
1414
use Composer\Plugin\PluginInterface;
15+
use Composer\Script\Event;
16+
use Composer\Script\ScriptEvents;
1517

1618
final class NoFinalClassPlugin implements PluginInterface, EventSubscriberInterface
1719
{
@@ -27,6 +29,8 @@ public static function getSubscribedEvents()
2729
return [
2830
PackageEvents::POST_PACKAGE_INSTALL => 'onPackageInstall',
2931
PackageEvents::POST_PACKAGE_UPDATE => 'onPackageUpdate',
32+
ScriptEvents::POST_INSTALL_CMD => 'onInstallCmd',
33+
ScriptEvents::POST_UPDATE_CMD => 'onUpdateCmd',
3034
];
3135
}
3236

@@ -56,10 +60,20 @@ public function onPackageUpdate(PackageEvent $event)
5660
$this->removeFinalFromAllEasyAdminClasses();
5761
}
5862

63+
public function onInstallCmd(Event $event)
64+
{
65+
$this->removeFinalFromAllEasyAdminClasses();
66+
}
67+
68+
public function onUpdateCmd(Event $event)
69+
{
70+
$this->removeFinalFromAllEasyAdminClasses();
71+
}
72+
5973
public function removeFinalFromAllEasyAdminClasses()
6074
{
6175
$vendorDirPath = $this->getVendorDirPath();
62-
$easyAdminDirPath = $vendorDirPath.'/easycorp/easyadmin-bundle';
76+
$easyAdminDirPath = $vendorDirPath . '/easycorp/easyadmin-bundle';
6377
foreach ($this->getFilePathsOfAllEasyAdminClasses($easyAdminDirPath) as $filePath) {
6478
file_put_contents(
6579
$filePath,
@@ -95,7 +109,7 @@ private function getVendorDirPath(): string
95109
$composerJsonContents = json_decode(file_get_contents($composerJsonFilePath), associative: true, flags: JSON_THROW_ON_ERROR);
96110
$projectDir = dirname(realpath($composerJsonFilePath));
97111

98-
return $composerJsonContents['config']['vendor-dir'] ?? $projectDir.'/vendor';
112+
return $composerJsonContents['config']['vendor-dir'] ?? $projectDir . '/vendor';
99113
}
100114

101115
/**

0 commit comments

Comments
 (0)