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:
Nicolas Grekas 2016-11-24 11:38:47 +01:00
commit b928133bbe
3 changed files with 43 additions and 4 deletions

View File

@ -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()) {

View File

@ -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')));

View File

@ -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
{
}