Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit035c409

Browse files
committed
do not inline service factories
The `XmlDumper`, which is used in the full-stack framework to dump theused container, is not capable to dump inlined factories.
1 parent900558c commit035c409

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-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/Compiler/InlineServiceDefinitionsPassTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ public function testProcessDoesNotInlineWhenServiceReferencesItself()
237237
$this->assertSame($ref,$calls[0][1][0]);
238238
}
239239

240+
publicfunctiontestProcessDoesNotInlineFactories()
241+
{
242+
$container =newContainerBuilder();
243+
$container
244+
->register('foo.factory')
245+
->setPublic(false)
246+
;
247+
$container
248+
->register('foo')
249+
->setFactory(array(newReference('foo.factory'),'getFoo'))
250+
;
251+
$this->process($container);
252+
253+
$factory =$container->getDefinition('foo')->getFactory();
254+
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference',$factory[0]);
255+
}
256+
240257
protectedfunctionprocess(ContainerBuilder$container)
241258
{
242259
$repeatedPass =newRepeatedPass(array(newAnalyzeServiceReferencesPass(),newInlineServiceDefinitionsPass()));

‎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
protectedfunctiongetNewFactoryServiceService()
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+
protectedfunctiongetNewFactoryService()
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)

[8]ページ先頭

©2009-2025 Movatter.jp