Repository navigation
feat(core): take aspects from the application's PSR-11 container - #769
Draft
lisachenko wants to merge 1 commit into
Draft
lisachenko wants to merge 1 commit into
lisachenko wants to merge 1 commit into
Conversation
AspectContainer::setDelegate() attaches the PSR-11 container of the application once it exists: get()/has() fall back to it for ids that are not registered here, guarded against composite containers that ask back. addDelegatedService() registers a lazy service whose instance is fetched from the delegate on first use, so aspects with dependencies are declared in configureAop() while weaving and cache warm-up never need the delegate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JzyTe7njn5wEgo3sGxfjYR
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #769 +/- ##
============================================
+ Coverage 97.82% 97.83% +0.01%
- Complexity 1847 1858 +11
============================================
Files 105 105
Lines 4867 4898 +31
============================================
+ Hits 4761 4792 +31
Misses 106 106 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Follow-up to #768: aspects (and their dependencies) can now come from the application's own PSR-11 container (Symfony, Laravel, PHP-DI, ...).
The AOP kernel is initialized before the application builds its container, so registration and lookup are split:
AspectContainer::setDelegate(ContainerInterface $delegate):get()/has()fall back to the delegate on a miss only (the woven-code pathThe::advice()/The::aspect()always hits local entries, so it's unchanged). Delegated values are not stored locally; the delegate owns their lifecycle. A re-entrancy guard stops a composite delegate that contains this container (the PSR-11 delegate-lookup pattern) from recursing forever. Self-delegation is rejected.AspectContainer::addDelegatedService(class-string $id, ?string $delegateId = null)isaddLazyService()whose factory fetches from the delegate. The service is tagged and collected as usual, but materializes as a native lazy proxy, so weaving, compiled advisor caches andbin/aspect cache:warmup:aopnever need the delegate. The instance is fetched on the first advice call and must be an instance of$id.setDelegate(), or the delegate returns the wrong type →ContainerExceptionwith a message saying what to do.add()/addLazyService()instead.===is not.Docs: new "Aspects from the application container" section in
docs/configuration.md, plus README, CHANGELOG, UPGRADE-4.0.md (customcontainerClassimplementations add the two methods) andsrc/Core/AGENTS.md.Transformer wiring is untouched (no
AspectKernel/FrameworkServices/transformer changes), so the transformation performance group isn't affected.Checklist
type(scope): summary)ContainerTest: fallback, local entries win, self-delegation rejected, composite delegate doesn't loop (verified it recurses without the guard), delegated service built only on first use after the aspects were collected, custom delegate id, use beforesetDelegate(), wrong type, property-less class. FunctionalDelegatedServiceTest/ProductionDelegatedServiceTest: the fixture kernel registersGreetingAspectviaaddDelegatedService(), the cache is warmed up without any app container, andbin/delegated-aspect.phpbuilds a small PSR-11ApplicationContainer, attaches it and runs the wovenGreeter("Hello, World!"), in debug and production mode.composer checkpasses (cs, phpstan level 10, phpunit 3128 tests)Generated by Claude Code