5.next: Option B - Simpler opt-in CakePHP container#19366
Open
dereuromark wants to merge 5 commits intocakephp:5.nextfrom
Open
5.next: Option B - Simpler opt-in CakePHP container#19366dereuromark wants to merge 5 commits intocakephp:5.nextfrom
dereuromark wants to merge 5 commits intocakephp:5.nextfrom
Conversation
This adds a simpler alternative approach (Option B) for making the built-in
CakePHP container available as an opt-in feature for 5.4.
Key changes:
- Add ContainerFactory to select container based on Configure setting
- Update type hints to accept both ContainerInterface and CakeContainer
- Remove League-specific traits from ComponentRegistry
- Use PSR interface for exception catching
To opt-in to the CakePHP container:
Configure::write('App.container', 'cake');
This approach:
- Keeps ~100 lines of code vs ~450 lines in the adapter approach
- Zero BC impact for users who don't switch containers
- Accepts minor app changes for those who do switch
- No adapter/wrapper complexity
Refs: cakephp#19358
Uses a bridge pattern that wraps CakePHP's Container to implement ContainerInterface, maintaining 100% backwards compatibility: - CakeContainerBridge wraps Cake\Container\Container - CakeDefinitionBridge wraps definitions for League interface compat - CakeInflectorBridge wraps inflectors for League interface compat No interface changes required - existing implementations continue to work unchanged. Users can opt into the CakePHP container via config.
- Revert interface union types to maintain BC - Add getTags() method for league/container 5.2 compatibility
Required for compatibility with league/container 5.2 which added this method to its DefinitionInterface.
This was referenced Mar 28, 2026
LordSimal
approved these changes
Mar 28, 2026
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.
Alternative to #19358
This PR implements Option B from my comment on #19358 - a simpler approach to making the built-in CakePHP container available as opt-in for 5.4.
Summary
ContainerFactoryto select container based onConfigure::read('App.container')ContainerInterfaceandCakeContainerComponentRegistry(uses simpler inline logic)Usage
To opt-in to the CakePHP container:
Comparison
Trade-offs
Advantages:
Disadvantages:
Why this is pragmatic
add,addShared,get,has) which works identicallyRefs: #19358, #18090