From dfa210dfc7152ddc1e786d379bb2017b240b0f39 Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Mon, 12 Oct 2026 17:33:34 +0200 Subject: [PATCH] refactor: let the WpCli module run without Laravel's application WpCliDiscovery builds commands through the discovery's instance pool instead of resolve(). An architecture test keeps the module, provider and generator aside, to the attributes, discovery, PSR logging and WP-CLI. --- CHANGELOG.md | 1 + .../Services/WpCliDiscovery.php | 9 ++------ tests/Unit/WpCli/PackageBoundaryTest.php | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 tests/Unit/WpCli/PackageBoundaryTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 489ebf97..59f08d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The discovery benchmarks measure memory as PHP allocates it, from a reset peak: they read 2 MB whatever the load - `#[WpRestRoute\Method]` no longer registers its route: `WpRestRouteRegistrar`, in the WpRest module, does, with the same arguments, permissions and request injection. Default slugs, meta keys and command names come from `Pollora\Attributes\Support\Naming`, which gives the same results as `Str::kebab()` and `Str::snake()`; `Pollora\Support\Slug` uses it - The WpRest module no longer reaches for Laravel's application, the first step towards `pollora/wp-rest`: custom `HandlesAttributes` attributes receive the PSR-11 container given to `WpRestDiscovery`, and `WpRestAttributableWrapper` takes the controller instance instead of building it. An architecture test keeps the module to the attributes, discovery, PSR contracts and WordPress +- The WpCli module no longer reaches for Laravel's application, the first step towards `pollora/wp-cli`: `WpCliDiscovery` builds commands through the discovery's instance pool instead of `resolve()`. Its service provider and `pollora:make:wp-cli` stay in the framework; an architecture test keeps the rest to the attributes, discovery, PSR logging and WP-CLI ### Deprecated - `DiscoveryCacheInterface` and `LaravelDiscoveryCache`, removed in 15.0: nothing reads this cache, scans are cached by the Spatie driver given to `DiscoveryCacheManager` diff --git a/src/WpCli/Infrastructure/Services/WpCliDiscovery.php b/src/WpCli/Infrastructure/Services/WpCliDiscovery.php index 36c9baeb..17d8ba33 100644 --- a/src/WpCli/Infrastructure/Services/WpCliDiscovery.php +++ b/src/WpCli/Infrastructure/Services/WpCliDiscovery.php @@ -129,13 +129,8 @@ private function processWpCliCommand(string $className, ?ReflectionCacheInterfac */ private function getCommandInstance(string $className): object { - // Use instance pool if available, otherwise fallback to local cache - return $this->getInstanceFromPool($className, function () use ($className): object { - // On laisse le container gérer la construction - $this->commandInstances[$className] ??= resolve($className); - - return $this->commandInstances[$className]; - }); + // The instance pool builds it with its dependencies; one instance per class + return $this->commandInstances[$className] ??= $this->getInstanceFromPool($className); } /** diff --git a/tests/Unit/WpCli/PackageBoundaryTest.php b/tests/Unit/WpCli/PackageBoundaryTest.php new file mode 100644 index 00000000..8fb39eb2 --- /dev/null +++ b/tests/Unit/WpCli/PackageBoundaryTest.php @@ -0,0 +1,23 @@ +expect('Pollora\WpCli') + ->toOnlyUse([ + 'Pollora\WpCli', + 'Pollora\Attributes', + 'Pollora\Discovery', + 'Psr\Log', + 'Spatie\StructureDiscoverer', + ]) + ->ignoring([WpCliServiceProvider::class, WpCliMakeCommand::class, 'WP_CLI', 'WP_CLI_Command']);