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

Refactor object() to create() and autowire() #449

Merged
merged 20 commits into from Apr 15, 2017
Merged

Conversation

@mnapoli
Copy link
Member

mnapoli commented Jan 1, 2017

Fixes #294, see #395 for more explanations.

The main goal is to simplify DI\object() by replacing it with DI\autowire() and DI\create().

autowire() and create() will not extend the previous definition (when using multiple configuration files). That will be much clearer.

Because of that, we need to have an autowire() helper that will explicitly autowire the service (and let us override just some parameters). It has the benefit of being much more explicit.

  • add DI\create() with the same signature as DI\object()
  • DI\create() must not extend the previous entry with the same name
    • add test for that
  • DI\create() must not go through autowiring
    • add test for that
  • add DI\autowire() with the same signature as DI\object() but calls autowiring
  • remove DI\object() entirely
  • update the documentation
  • changelog
  • upgrade guide

Will fix:


Extract of the migration guide:

The DI\object() function helper has been removed. You should use DI\create() or DI\autowire() instead.

What should you do with your DI\object() definitions:

  • if you disabled autowiring:
    • replace it with DI\create() and everything should work
  • if you use autowiring:
    • replace it with DI\create() for definitions that replace autowiring completely (i.e. those that redefine all the parameters)
    • replace it with DI\autowire() for definitions that just define some parameters and let autowiring guess the rest of the parameters

If you have a single configuration file, that's it.

If you have multiple configuration files, for example if you have built a module system, then there is one thing to be aware of: DI\object() used to extend previous definitions. create() and autowire() do not extend previous definitions, they completely override them, and this is intended. The behavior of object() was confusing and hard to understand, the new helpers are more predictable and simple.

@mnapoli mnapoli added the enhancement label Jan 1, 2017
@mnapoli mnapoli added this to the 6.0 milestone Jan 1, 2017
@mnapoli mnapoli self-assigned this Jan 1, 2017
mnapoli added 19 commits Jan 1, 2017
`object()` extended the previous entry, `create()` doesn't.
`object()` extended the autowired definition, `create()` doesn't.
…eter()` methods...

... because they extend nothing. Only `constructor()` and `method()` can be used.
# Conflicts:
#	tests/UnitTest/Definition/Helper/AutowireDefinitionHelperTest.php
@mnapoli mnapoli changed the title WIP: Refactor DI\object() to DI\create() Refactor DI\object() to DI\create() Apr 15, 2017
@mnapoli mnapoli changed the title Refactor DI\object() to DI\create() Refactor DI\object() to DI\create() and DI\autowire() Apr 15, 2017
@mnapoli mnapoli changed the title Refactor DI\object() to DI\create() and DI\autowire() Refactor object() to create() and autowire() Apr 15, 2017
@mnapoli mnapoli merged commit ff03746 into 6.0 Apr 15, 2017
2 of 6 checks passed
2 of 6 checks passed
Scrutinizer Created
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
coverage/coveralls Coverage pending from Coveralls.io
Details
continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/styleci/push The StyleCI analysis has passed
Details
@mnapoli mnapoli mentioned this pull request Apr 15, 2017
@mnapoli mnapoli deleted the refactor-object-to-create branch Apr 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.