-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Support local binding #22187
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
Changes from 1 commit
6e1be02
f179bb6
e3c5999
316b818
24b29d9
e30e63e
35fcc43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,7 @@ private function getServiceDefaults(\DOMDocument $xml, $file) | |
} | ||
$defaults = array( | ||
'tags' => $this->getChildren($defaultsNode, 'tag'), | ||
'bind' => array_map(function ($v) { | ||
return new BoundArgument($v); | ||
}, $this->getArgumentsAsPhp($defaultsNode, 'bind', $file)), | ||
'bind' => array_map(function ($v) { return new BoundArgument($v); }, $this->getArgumentsAsPhp($defaultsNode, 'bind', $file)), | ||
); | ||
|
||
foreach ($defaults['tags'] as $tag) { | ||
|
@@ -358,6 +356,8 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults) | |
|
||
$bindings = $this->getArgumentsAsPhp($service, 'bind', $file); | ||
if (isset($defaults['bind'])) { | ||
// deep clone, to avoid multiple process of the same instance in the | ||
// passes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment should be on one line |
||
$bindings = array_merge(unserialize(serialize($defaults['bind'])), $bindings); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small comment needed to explain the deep clone |
||
} | ||
if ($bindings) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,9 +294,7 @@ private function parseDefaults(array &$content, $file) | |
throw new InvalidArgumentException(sprintf('Parameter "bind" in "_defaults" must be an array in %s. Check your YAML syntax.', $file)); | ||
} | ||
|
||
$defaults['bind'] = array_map(function ($v) { | ||
return new BoundArgument($v); | ||
}, $this->resolveServices($defaults['bind'], $file)); | ||
$defaults['bind'] = array_map(function ($v) { return new BoundArgument($v); }, $this->resolveServices($defaults['bind'], $file)); | ||
} | ||
|
||
return $defaults; | ||
|
@@ -537,7 +535,10 @@ private function parseDefinition($id, $service, $file, array $defaults) | |
} | ||
|
||
if (isset($defaults['bind']) || isset($service['bind'])) { | ||
// deep clone, to avoid multiple process of the same instance in the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
// passes | ||
$bindings = isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment need |
||
|
||
if (isset($service['bind'])) { | ||
if (!is_array($service['bind'])) { | ||
throw new InvalidArgumentException(sprintf('Parameter "bind" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add some explanations, eg:
Bindings map $named arguments or type-hints to values that should be injected in the matching parameters of the constructor and of setters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adapted a bit your proposal to:
Ok for you?