-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Avoid call_user_func in dumped containers. #9807
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,6 +487,12 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta | |
return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
} | ||
|
||
$class = $this->dumpValue($callable[0]); | ||
// If the class is a string we can optimize call_user_func away | ||
if (strpos($class, "'") === 0) { | ||
return sprintf(" %s::%s(\$%s);\n", substr($class, 1, -1), $callable[1], $variableName); | ||
} | ||
|
||
return sprintf(" call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
} | ||
|
||
|
@@ -691,6 +697,13 @@ private function addNewInstance($id, Definition $definition, $return, $instantia | |
|
||
if (null !== $definition->getFactoryMethod()) { | ||
if (null !== $definition->getFactoryClass()) { | ||
$class = $this->dumpValue($definition->getFactoryClass()); | ||
|
||
// If the class is a string we can optimize call_user_func away | ||
if (strpos($class, "'") === 0) { | ||
return sprintf(" $return{$instantiation}%s::%s(%s);\n", substr($class, 1, -1), $definition->getFactoryMethod(), $arguments ? implode(', ', $arguments) : ''); | ||
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. @realityking: This change has caused Doctrine ODM Bundle to break, and any similar bundles that use factory class.
Notice that 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. Thanks for the info. There's a fix in progress here: #9816 |
||
} | ||
|
||
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : ''); | ||
} | ||
|
||
|
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.
The class name should be dumped as a fully qualified class name, not as a class name relative to the global namespace, to support dumping containers in a namespace
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.
You mean just adding a
\
in front of the class. Correct?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.
yes. It is not needed when it is dumped in a string for call_user_func, but it is needed for the direct call