[DependencyInjection] Avoid call_user_func in dumped containers.
This commit is contained in:
parent
67ae8fab19
commit
be1eaaae9a
@ -487,6 +487,12 @@ class PhpDumper extends Dumper
|
||||
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 @@ EOF;
|
||||
|
||||
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) : '');
|
||||
}
|
||||
|
||||
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ class ProjectServiceContainer extends Container
|
||||
{
|
||||
$a = $this->get('foo.baz');
|
||||
|
||||
$this->services['foo'] = $instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')), true, $this);
|
||||
$this->services['foo'] = $instance = FooClass::getInstance('foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')), true, $this);
|
||||
|
||||
$instance->setBar($this->get('bar'));
|
||||
$instance->initialize();
|
||||
|
@ -148,7 +148,7 @@ class ProjectServiceContainer extends Container
|
||||
{
|
||||
$a = $this->get('foo.baz');
|
||||
|
||||
$this->services['foo'] = $instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
|
||||
$this->services['foo'] = $instance = FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
|
||||
|
||||
$instance->setBar($this->get('bar'));
|
||||
$instance->initialize();
|
||||
@ -169,9 +169,9 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getFoo_BazService()
|
||||
{
|
||||
$this->services['foo.baz'] = $instance = call_user_func(array('BazClass', 'getInstance'));
|
||||
$this->services['foo.baz'] = $instance = BazClass::getInstance();
|
||||
|
||||
call_user_func(array('BazClass', 'configureStatic1'), $instance);
|
||||
BazClass::configureStatic1($instance);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user