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

Inject dependencies and requested entry name in factory parameters [retake of #345] #347

Merged
merged 12 commits into from Nov 29, 2015

Conversation

Projects
None yet
3 participants
@mnapoli
Member

mnapoli commented Nov 29, 2015

This PR contains #345 and #333.

The differences with #345:

  • optimizations: from my profilings we went from a 25% slowdown on factories to 0%, so 5.2 should not be slower than 5.1 (that was the main blocker for me)
  • factories can inject a new object (DI\Factory\RequestedEntry) to know the requested definition name: that replaces the injection of Definition instances. The reason for that is to avoid coupling user factories with definitions which are an implementation detail of PHP-DI. If definitions ever change, it will not break factories.

Example to get the requested entry name:

factory(function(ContainerInterface $c, RequestedEntry $e) {
    return new Thing($c->get($e->getName()));
});

Example to inject other services:

factory(function(Logger $logger, Mailer $mailer) {
    return new Thing($logger, $mailer);
});

TODO:

  • update changelog
  • documentation

This is the last feature planned for 5.2, after that it's release time!

jdreesen and others added some commits Sep 21, 2015

Allow injection of current definition instance as factory parameter
Current Definition can be injected via type-hinting: DI\Definition\Definition
or as a second parameter if no type-hinting is present.

Docs and tests updated accordingly.
Inject a new DI\Factory\RequestedEntry object instead of definitions …
…into factories

That allows to keep definitions an internal implementation details. If definitions are refactored later on, factories will not be broken. Also factories have no reason to know about definitions, they just want the request entry name (ISP).

@mnapoli mnapoli added the enhancement label Nov 29, 2015

@mnapoli mnapoli added this to the 5.2 milestone Nov 29, 2015

@quimcalpe

This comment has been minimized.

Show comment
Hide comment
@quimcalpe

quimcalpe Nov 29, 2015

Contributor

Nice optimization passing container in constructor and resolving directly, then you can avoid TypeHintContainerResolver in resolver chain 👍
RequestedEntry is also cleaner... so 2 big thumbs up! 👍 👍

Contributor

quimcalpe commented Nov 29, 2015

Nice optimization passing container in constructor and resolving directly, then you can avoid TypeHintContainerResolver in resolver chain 👍
RequestedEntry is also cleaner... so 2 big thumbs up! 👍 👍

@mnapoli

This comment has been minimized.

Show comment
Hide comment
@mnapoli

mnapoli Nov 29, 2015

Member

Thanks! Time to merge then :)

Member

mnapoli commented Nov 29, 2015

Thanks! Time to merge then :)

mnapoli added a commit that referenced this pull request Nov 29, 2015

Merge pull request #347 from PHP-DI/345
Inject dependencies and requested entry name in factory parameters [retake of #345]

@mnapoli mnapoli merged commit 773145e into master Nov 29, 2015

5 checks passed

Scrutinizer 1 new issues, 6 updated code elements
Details
StyleCI The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.4%) to 84.559%
Details

@mnapoli mnapoli deleted the 345 branch Nov 29, 2015

@jdreesen

This comment has been minimized.

Show comment
Hide comment
@jdreesen

jdreesen Nov 29, 2015

Contributor

Looks very nice 👍

Contributor

jdreesen commented Nov 29, 2015

Looks very nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment