8000 do not inline service factories · symfony/symfony@416eee2 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/sessions-d044b7c46be3.js" defer="defer">

Commit 416eee2

Browse files
committed
do not inline service factories
The `XmlDumper`, which is used in the full-stack framework to dump the used container, is not capable to dump inlined factories.
1 parent 900558c commit 416eee2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public function process(ContainerBuilder $container)
6565

6666
$configurator = $this->inlineArguments($container, array($definition->getConfigurator()));
6767
$definition->setConfigurator($configurator[0]);
68-
69-
$factory = $this->inlineArguments($container, array($definition->getFactory()));
70-
$definition->setFactory($factory[0]);
7168
}
7269
}
7370

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct()
4747
'foo_bar' => 'getFooBarService',
4848
'foo_with_inline' => 'getFooWithInlineService',
4949
'method_call1' => 'getMethodCall1Service',
50+
'new_factory' => 'getNewFactoryService',
5051
'new_factory_service' => 'getNewFactoryServiceService',
5152
'request' => 'getRequestService',
5253
'service_from_static_method' => 'getServiceFromStaticMethodService',
@@ -282,10 +283,7 @@ protected function getMethodCall1Service()
282283
*/
283284
protected function getNewFactoryServiceService()
284285
{
285-
$a = new \FactoryClass();
286-
$a->foo = 'bar';
287-
288-
$this->services['new_factory_service'] = $instance = $a->getInstance();
286+
$this->services['new_factory_service'] = $instance = $this->get('new_factory')->getInstance();
289287

290288
$instance->foo = 'bar';
291289

@@ -328,6 +326,27 @@ protected function synchronizeRequestService()
328326
}
329327
}
330328

329+
/**
330+
* Gets the 'new_factory' service.
331+
*
332+
* This service is shared.
333+
* This method always returns the same instance of the service.
334+
*
335+
* This service is private.
336+
* If you want to be able to request this service from the container directly,
337+
* make it public, otherwise you might end up with broken code.
338+
*
339+
* @return \FactoryClass A FactoryClass instance.
340+
*/
341+
protected function getNewFactoryService()
342+
{
343+
$this->services['new_factory'] = $instance = new \FactoryClass();
344+
345+
$instance->foo = 'bar';
346+
347+
return $instance;
348+
}
349+
331350
/**
332351
* {@inheritdoc}
333352
*/

0 commit comments

Comments
 (0)
0