Skip to content

Commit 9db2a9c

Browse files
committed
[DependencyInjection] Avoid generating call_user_func in more cases
1 parent 2bfd6b9 commit 9db2a9c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta
542542
return sprintf(" %s::%s(\$%s);\n", $this->dumpLiteralClass($class), $callable[1], $variableName);
543543
}
544544

545+
if (strpos($class, 'new') === 0) {
546+
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
547+
}
548+
545549
return sprintf(" call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
546550
}
547551

@@ -723,6 +727,10 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
723727
return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
724728
}
725729

730+
if (strpos($class, 'new') === 0) {
731+
return sprintf(" $return{$instantiation}(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
732+
}
733+
726734
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
727735
}
728736

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct()
4040
*/
4141
protected function getServiceFromAnonymousFactoryService()
4242
{
43-
return $this->services['service_from_anonymous_factory'] = call_user_func(array(new \Bar\FooClass(), 'getInstance'));
43+
return $this->services['service_from_anonymous_factory'] = (new \Bar\FooClass())->getInstance();
4444
}
4545

4646
/**

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function getConfiguredServiceSimpleService()
128128
{
129129
$this->services['configured_service_simple'] = $instance = new \stdClass();
130130

131-
call_user_func(array(new \ConfClass('bar'), 'configureStdClass'), $instance);
131+
(new \ConfClass('bar'))->configureStdClass($instance);
132132

133133
return $instance;
134134
}
@@ -199,7 +199,7 @@ protected function getFactoryServiceService()
199199
*/
200200
protected function getFactoryServiceSimpleService()
201201
{
202-
return $this->services['factory_service_simple'] = call_user_func(array(new \SimpleFactoryClass('foo'), 'getInstance'));
202+
return $this->services['factory_service_simple'] = (new \SimpleFactoryClass('foo'))->getInstance();
203203
}
204204

205205
/**

0 commit comments

Comments
 (0)