Skip to content

Commit 0a61402

Browse files
Merge branch '3.2'
* 3.2: Fix merge [DI] Fixed custom services definition BC break introduced in ec7e70f… [HttpKernel] Deprecate checking for cacheable HTTP methods in Request::isMethodSafe() [Process] Fix kill process on reached timeout using getIterator() [DI] Aliases should preserve the aliased invalid behavior
2 parents 93f50bf + 99f3c3a commit 0a61402

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
424424
}
425425

426426
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
427-
return $this->get($this->aliasDefinitions[$id]);
427+
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
428428
}
429429

430430
try {
@@ -835,8 +835,8 @@ public function findDefinition($id)
835835
*/
836836
private function createService(Definition $definition, $id, $tryProxy = true)
837837
{
838-
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
839-
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
838+
if ($definition instanceof DefinitionDecorator) {
839+
throw new RuntimeException(sprintf('Constructing service "%s" from a parent definition is not supported at build time.', $id));
840840
}
841841

842842
if ($definition->isSynthetic()) {

Tests/ContainerBuilderTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2929
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
3030
use Symfony\Component\Config\Resource\FileResource;
31+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
3132
use Symfony\Component\ExpressionLanguage\Expression;
3233

3334
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -266,6 +267,18 @@ public function testSetReplacesAlias()
266267
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
267268
}
268269

270+
public function testAliasesKeepInvalidBehavior()
271+
{
272+
$builder = new ContainerBuilder();
273+
274+
$aliased = new Definition('stdClass');
275+
$aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
276+
$builder->setDefinition('aliased', $aliased);
277+
$builder->setAlias('alias', 'aliased');
278+
279+
$this->assertEquals(new \stdClass(), $builder->get('alias'));
280+
}
281+
269282
public function testAddGetCompilerPass()
270283
{
271284
$builder = new ContainerBuilder();
@@ -415,7 +428,7 @@ public function testResolveServices()
415428

416429
/**
417430
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
418-
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
431+
* @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
419432
*/
420433
public function testResolveServicesWithDecoratedDefinition()
421434
{
@@ -427,6 +440,14 @@ public function testResolveServicesWithDecoratedDefinition()
427440
$builder->get('foo');
428441
}
429442

443+
public function testResolveServicesWithCustomDefinitionClass()
444+
{
445+
$builder = new ContainerBuilder();
446+
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
447+
448+
$this->assertInstanceOf('stdClass', $builder->get('foo'));
449+
}
450+
430451
public function testMerge()
431452
{
432453
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));

Tests/Fixtures/CustomDefinition.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
use Symfony\Component\DependencyInjection\Definition;
15+
16+
class CustomDefinition extends Definition
17+
{
18+
}

0 commit comments

Comments
 (0)