Refactor object() to create() and autowire()#449
Merged
Conversation
`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
This was referenced Apr 15, 2017
Closed
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.
Fixes #294, see #395 for more explanations.
The main goal is to simplify
DI\object()by replacing it withDI\autowire()andDI\create().autowire()andcreate()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.DI\create()with the same signature asDI\object()DI\create()must not extend the previous entry with the same nameDI\create()must not go through autowiringDI\autowire()with the same signature asDI\object()but calls autowiringDI\object()entirelyWill fix:
Extract of the migration guide:
The
DI\object()function helper has been removed. You should useDI\create()orDI\autowire()instead.What should you do with your
DI\object()definitions:DI\create()and everything should workDI\create()for definitions that replace autowiring completely (i.e. those that redefine all the parameters)DI\autowire()for definitions that just define some parameters and let autowiring guess the rest of the parametersIf 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()andautowire()do not extend previous definitions, they completely override them, and this is intended. The behavior ofobject()was confusing and hard to understand, the new helpers are more predictable and simple.