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

Appearance settings

[DependencyInjection] do not inline service factories #13914

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

Merged
merged 1 commit into from
Mar 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
xabbuh committed Mar 16, 2015
commit 663ae9f5aa9183eeff49bbfd46c7caee1e9aa66c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public function process(ContainerBuilder $container)

$configurator = $this->inlineArguments($container, array($definition->getConfigurator()));
$definition->setConfigurator($configurator[0]);

$factory = $this->inlineArguments($container, array($definition->getFactory()));
$definition->setFactory($factory[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ public function testProcessDoesNotInlineWhenServiceReferencesItself()
$this->assertSame($ref, $calls[0][1][0]);
}

public function testProcessDoesNotInlineFactories()
{
$container = new ContainerBuilder();
$container
->register('foo.factory')
->setPublic(false)
;
$container
->register('foo')
->setFactory(array(new Reference('foo.factory'), 'getFoo'))
;
$this->process($container);

$factory = $container->getDefinition('foo')->getFactory();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factory[0]);
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,26 @@ public function provideDecoratedServicesData()
", include $fixturesPath.'/containers/container16.php'),
);
}

/**
* @dataProvider provideCompiledContainerData
*/
public function testCompiledContainerCanBeDumped($containerFile)
{
$fixturesPath = __DIR__.'/../Fixtures';
$container = require $fixturesPath.'/containers/'.$containerFile.'.php';
$container->compile();
$dumper = new XmlDumper($container);
$dumper->dump();
}

public function provideCompiledContainerData()
{
return array(
array('container8'),
array('container11'),
array('container12'),
array('container14'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct()
'foo_bar' => 'getFooBarService',
'foo_with_inline' => 'getFooWithInlineService',
'method_call1' => 'getMethodCall1Service',
'new_factory' => 'getNewFactoryService',
'new_factory_service' => 'getNewFactoryServiceService',
'request' => 'getRequestService',
'service_from_static_method' => 'getServiceFromStaticMethodService',
Expand Down Expand Up @@ -282,10 +283,7 @@ protected function getMethodCall1Service()
*/
protected function getNewFactoryServiceService()
{
$a = new \FactoryClass();
$a->foo = 'bar';

$this->services['new_factory_service'] = $instance = $a->getInstance();
$this->services['new_factory_service'] = $instance = $this->get('new_factory')->getInstance();

$instance->foo = 'bar';

Expand Down Expand Up @@ -328,6 +326,27 @@ protected function synchronizeRequestService()
}
}

/**
* Gets the 'new_factory' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \FactoryClass A FactoryClass instance.
*/
protected function getNewFactoryService()
{
$this->services['new_factory'] = $instance = new \FactoryClass();

$instance->foo = 'bar';

return $instance;
}

/**
* {@inheritdoc}
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.