Skip to content

Allow ServiceDefinition::setArguments() to use previously set arguments #171

Description

@czukowski

Currently, it is possible to use setArguments() method of ServiceDefinition to set partial arguments and have the rest autowired:

$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[3] = $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 setArguments still does the job. Maybe we could have a different method to merge arguments passed into the current list, such as addArguments or mergeArguments? (these two names don't sound perfect though)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions