Skip to content

Commit a003380

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: [DependencyInjection] fixed service resolution for factories [acl][command][SecurityBundle] Fixed user input option mode to be an Array Conflicts: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
2 parents b178ee5 + d2fc77e commit a003380

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function configure()
7878
EOF
7979
)
8080
->addArgument('arguments', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of permissions and object identities (class name and ID separated by a column)')
81-
->addOption('user', null, InputOption::VALUE_REQUIRED, 'A list of security identities')
81+
->addOption('user', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of security identities')
8282
->addOption('role', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of roles')
8383
->addOption('class-scope', null, InputOption::VALUE_NONE, 'Use class-scope entries')
8484
;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function process(ContainerBuilder $container)
3737
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
3838
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
3939
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
40+
if ($definition->getFactoryClass(false)) {
41+
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass()));
42+
}
4043

4144
$calls = array();
4245
foreach ($definition->getMethodCalls() as $name => $arguments) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,9 @@ private function dumpValue($value, $interpolate = true)
13381338
if (null !== $value->getFactoryClass(false)) {
13391339
return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass(false)), $value->getFactoryMethod(false), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
13401340
} elseif (null !== $value->getFactoryService(false)) {
1341-
return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments));
1341+
$service = $this->dumpValue($definition->getFactoryService(false));
1342+
1343+
return sprintf("%s->%s(%s)", 0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments));
13421344
} else {
13431345
throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
13441346
}

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,42 @@ public function testCreateServiceFactory()
333333
$this->assertTrue($builder->get('baz')->called, '->createService() uses another service as factory');
334334
}
335335

336+
public function testLegacyCreateServiceFactory()
337+
{
338+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
339+
340+
$builder = new ContainerBuilder();
341+
$builder->register('bar', 'Bar\FooClass');
342+
$builder
343+
->register('foo1', 'Bar\FooClass')
344+
->setFactoryClass('%foo_class%')
345+
->setFactoryMethod('getInstance')
346+
->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')))
347+
;
348+
$builder->setParameter('value', 'bar');
349+
$builder->setParameter('foo_class', 'Bar\FooClass');
350+
$this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
351+
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
352+
}
353+
354+
/**
355+
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
356+
*/
357+
public function testLegacyCreateServiceFactoryService()
358+
{
359+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
360+
361+
$builder = new ContainerBuilder();
362+
$builder->register('foo_service', 'Bar\FooClass');
363+
$builder
364+
->register('foo', 'Bar\FooClass')
365+
->setFactoryService('%foo_service%')
366+
->setFactoryMethod('getInstance')
367+
;
368+
$builder->setParameter('foo_service', 'foo_service');
369+
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
370+
}
371+
336372
/**
337373
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
338374
*/

0 commit comments

Comments
 (0)