Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow ServiceDefinition::setArguments() to use previously set arguments #171
Currently, it is possible to use
$builder->addDefinition(...) ->setFactory(...) ->setArguments([ 2 => $config['value'] ])
However, if we want to modify other arguments later, we can't use the same method because it'll throw away anything set previously, ie:
$builder->getDefinition(...) ->setArguments([ 3 => $config['another value'] // 2nd argument is now lost. ])
I think this behavior may be confusing since method principally does allow to set an incomplete list of arguments.
It is possible to do something like this, but it looks awkward to actually use such construct as the rest of the API is nice and concise:
$builder->getDefinition(...) ->getFactory() ->arguments = $config['another value']; // 2nd argument is now preserved.
On the other hand, being able to 'unset' previously set arguments may still be useful, and for that use case
Come to think of it, if the use case is to modify an argument (or arguments), a good method would be
If the idea sounds okay, I can submit a pull request, please let me know.
@dg what do you think about my other comment? I agree that changing the behavior of
While autowiring is one of the greatest features Nette has, it cannot be the answer for everything. There are at least two use cases when autowiring can't be used:
Acknowledging those use cases, a need for a convenient method to set individual arguments becomes apparent. I think adding a method to
The 'real' use case is to be able to modify services created by other extensions. I prefer creating a separate extension when the number of required modifications reaches a certain amount (while still being logically related), rather than dumping it all to a config file. Same if I need to extend a 3rd party extension in a considerable way.