Skip to content

Commit 2fd1f02

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: Reapply the change to allow to set the composer binary path [DependencyInjection] throw proper exception when decorating a synthetic service [WebLink] Sync type with parent interface [WebLink] fix types on Link::withAttribute() [ErrorHandler][DebugClassLoader] Do not check Phake mocks classes
2 parents 24371d4 + 100a042 commit 2fd1f02

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Compiler/DecoratorServicePass.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Alias;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1718
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1819
use Symfony\Component\DependencyInjection\Reference;
1920

@@ -70,6 +71,7 @@ public function process(ContainerBuilder $container)
7071
$public = $alias->isPublic();
7172
$private = $alias->isPrivate();
7273
$container->setAlias($renamedId, new Alias((string) $alias, false));
74+
$decoratedDefinition = $container->findDefinition($alias);
7375
} elseif ($container->hasDefinition($inner)) {
7476
$decoratedDefinition = $container->getDefinition($inner);
7577
$public = $decoratedDefinition->isPublic();
@@ -83,10 +85,15 @@ public function process(ContainerBuilder $container)
8385
} elseif (ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
8486
$public = $definition->isPublic();
8587
$private = $definition->isPrivate();
88+
$decoratedDefinition = null;
8689
} else {
8790
throw new ServiceNotFoundException($inner, $id);
8891
}
8992

93+
if ($decoratedDefinition && $decoratedDefinition->isSynthetic()) {
94+
throw new InvalidArgumentException(sprintf('A synthetic service cannot be decorated: service "%s" cannot decorate "%s".', $id, $inner));
95+
}
96+
9097
if (isset($decoratingDefinitions[$inner])) {
9198
$decoratingDefinition = $decoratingDefinitions[$inner];
9299

Tests/Compiler/DecoratorServicePassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1920
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2021
use Symfony\Component\DependencyInjection\Reference;
2122

@@ -261,6 +262,23 @@ public function testProcessLeavesServiceSubscriberTagOnOriginalDefinition()
261262
$this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar']], $container->getDefinition('baz')->getTags());
262263
}
263264

265+
public function testCannotDecorateSyntheticService()
266+
{
267+
$container = new ContainerBuilder();
268+
$container
269+
->register('foo')
270+
->setSynthetic(true)
271+
;
272+
$container
273+
->register('baz')
274+
->setDecoratedService('foo')
275+
;
276+
277+
$this->expectException(InvalidArgumentException::class);
278+
$this->expectExceptionMessage('A synthetic service cannot be decorated: service "baz" cannot decorate "foo".');
279+
$this->process($container);
280+
}
281+
264282
public function testGenericInnerReference()
265283
{
266284
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)