Merge branch '2.7' into 2.8
* 2.7: [DI] Fixed custom services definition BC break introduced in ec7e70fb… [DI] Aliases should preserve the aliased invalid behavior
This commit is contained in:
commit
b928133bbe
@ -449,7 +449,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
}
|
||||
|
||||
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
|
||||
return $this->get($this->aliasDefinitions[$id]);
|
||||
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -859,8 +859,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
*/
|
||||
public function createService(Definition $definition, $id, $tryProxy = true)
|
||||
{
|
||||
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
|
||||
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
|
||||
if ($definition instanceof DefinitionDecorator) {
|
||||
throw new RuntimeException(sprintf('Constructing service "%s" from a parent definition is not supported at build time.', $id));
|
||||
}
|
||||
|
||||
if ($definition->isSynthetic()) {
|
||||
|
@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
|
||||
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
@ -257,6 +258,18 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
|
||||
}
|
||||
|
||||
public function testAliasesKeepInvalidBehavior()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
|
||||
$aliased = new Definition('stdClass');
|
||||
$aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$builder->setDefinition('aliased', $aliased);
|
||||
$builder->setAlias('alias', 'aliased');
|
||||
|
||||
$this->assertEquals(new \stdClass(), $builder->get('alias'));
|
||||
}
|
||||
|
||||
public function testAddGetCompilerPass()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
@ -433,7 +446,7 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
|
||||
* @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
|
||||
*/
|
||||
public function testResolveServicesWithDecoratedDefinition()
|
||||
{
|
||||
@ -445,6 +458,14 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->get('foo');
|
||||
}
|
||||
|
||||
public function testResolveServicesWithCustomDefinitionClass()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
|
||||
|
||||
$this->assertInstanceOf('stdClass', $builder->get('foo'));
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class CustomDefinition extends Definition
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user