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

Support references to arbitrary container entries for factory definitions #321

Merged
merged 5 commits into from
Sep 15, 2015

Conversation

jdreesen
Copy link
Contributor

Currently, references to container entries in factory definitions are only possible, if they reference a class that actually exist with this exact FQN.

This PR enables you to to reference arbitrary container entries in factory definitions (as long as they are callables, of course), for example:

  • factory('my.closure')
  • factory('my.invocable.object')
  • factory(['my.class', 'method'])

Todo:

  • write tests
  • update documentation

Closes #272

@mnapoli
Copy link
Member

mnapoli commented Sep 12, 2015

👍

However is the change (current state of the PR) necessary? is_callable('A::b') is true (see https://3v4l.org/HgXfa)

@mnapoli mnapoli added this to the 5.2 milestone Sep 12, 2015
@jdreesen
Copy link
Contributor Author

Oh, I didn't know that this is possible! You are right, is_callable('A::b') is true for valid PHP callables (if class A actually exists).

But this change uses the container for callable resolution, too, which enables you to use any container entry name for the first part and thus allows something like: factory('foo.bar.baz::create')

@jdreesen
Copy link
Contributor Author

I just looked at the documentation where it says Please note: you can set any container entry name in the array, e.g. factory(['foo_bar_baz', 'create']), allowing you to configure foo_bar_baz and its dependencies like any other object.

This is actually not possible at the moment and would only be possible with the changes in this PR, too.

@mnapoli
Copy link
Member

mnapoli commented Sep 12, 2015

Mhh yeah that's true, 2 good points! I can't believe I didn't add tests in #308

@jdreesen
Copy link
Contributor Author

Added some unit tests that cover factory definitions that reference container entries.

Tests for Class::method callables are failing with dependencies=lowest, of course... should we raise the composer version for php-di/invoker to ^1.1?

@jdreesen jdreesen changed the title [WIP] Support 'Class::method` callables for factory definitions [WIP] Support references to container entries for factory definitions Sep 13, 2015
@jdreesen jdreesen changed the title [WIP] Support references to container entries for factory definitions [WIP] Support references to arbitrary container entries for factory definitions Sep 13, 2015
@jdreesen
Copy link
Contributor Author

Changed name and description of this PR to what it actually does.

@mnapoli
Copy link
Member

mnapoli commented Sep 13, 2015

should we raise the composer version for php-di/invoker to ^1.1?

makes sense to me, yep.

@jdreesen
Copy link
Contributor Author

Added some documentation (please tell me if you have suggestions for improvements on this :).

@jdreesen jdreesen changed the title [WIP] Support references to arbitrary container entries for factory definitions Support references to arbitrary container entries for factory definitions Sep 15, 2015
@mnapoli
Copy link
Member

mnapoli commented Sep 15, 2015

This is the cleanest pull request ever! Tests, docs, changelog! That rocks :)

mnapoli added a commit that referenced this pull request Sep 15, 2015
Support references to arbitrary container entries for factory definitions
@mnapoli mnapoli merged commit c9967ab into PHP-DI:master Sep 15, 2015
@jdreesen jdreesen deleted the paamayim-nekudotayim branch September 16, 2015 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants