Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use container as a factory #354

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

xepozz
Copy link
Contributor

@xepozz xepozz commented Feb 13, 2024

Q A
Is bugfix? /❌
New feature? ✔️
Breaks BC?
Fixed issues #350

Copy link

what-the-diff bot commented Feb 13, 2024

PR Summary

  • Enhancements to the Container class in src

    • Introduced a new constant called META_AFTER_BUILT
    • A new property afterBuiltHooks has been added; it'll presumably be used to perform certain actions after the container is fully constructed.
    • Two new methods, callHookAfterBuilt and setAfterBuiltHook, have been added. These methods are useful for setting up and invoking the newly introduced after-build hooks.
  • Addition of a new AfterBuiltHook class in src/Hook

    • A new class called AfterBuiltHook has been introduced in file AfterBuiltHook.php. It contains a static method unsetInstance that returns a closure. This likely facilitates the ability to work with hooks after a build.
  • Unit Testing for AfterBuiltHook class

    • A new unit test file tests/Unit/Hook/AfterBuiltHookTest.php has been added. It offers a test case for the AfterBuiltHook class, essentially checking if different objects are returned from the container after a build. This ensures the new functionality of the after-build hook is working as intended.

@@ -35,7 +35,8 @@ final class Container implements ContainerInterface
{
private const META_TAGS = 'tags';
private const META_RESET = 'reset';
private const ALLOWED_META = [self::META_TAGS, self::META_RESET];
private const META_AFTER_BUILT = 'afterBuilt';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other cases for this hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not now

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (aeb0856) to head (9ddc47e).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #354   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       161       166    +5     
===========================================
  Files             11        12    +1     
  Lines            466       479   +13     
===========================================
+ Hits             466       479   +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xepozz xepozz requested a review from a team February 23, 2024 07:14
@xepozz xepozz added the status:code review The pull request needs review. label Feb 23, 2024
Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know only one case for new hook (use container as factory for defined classes), I suggest don't add hook now. For this case more convient and clear will be use specific meta tag singleton with boolean value (true as default).

'singleton' => false

It is better than:

'afterBuilt' => AfterBuiltHook::unsetInstance(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants