14
14
use Symfony \Component \DependencyInjection \Alias ;
15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
16
use Symfony \Component \DependencyInjection \ContainerInterface ;
17
+ use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
17
18
use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
18
19
use Symfony \Component \DependencyInjection \Reference ;
19
20
@@ -59,6 +60,7 @@ public function process(ContainerBuilder $container)
59
60
$ public = $ alias ->isPublic ();
60
61
$ private = $ alias ->isPrivate ();
61
62
$ container ->setAlias ($ renamedId , new Alias ((string ) $ alias , false ));
63
+ $ decoratedDefinition = $ container ->findDefinition ($ alias );
62
64
} elseif ($ container ->hasDefinition ($ inner )) {
63
65
$ decoratedDefinition = $ container ->getDefinition ($ inner );
64
66
$ public = $ decoratedDefinition ->isPublic ();
@@ -72,10 +74,15 @@ public function process(ContainerBuilder $container)
72
74
} elseif (ContainerInterface::NULL_ON_INVALID_REFERENCE === $ invalidBehavior ) {
73
75
$ public = $ definition ->isPublic ();
74
76
$ private = $ definition ->isPrivate ();
77
+ $ decoratedDefinition = null ;
75
78
} else {
76
79
throw new ServiceNotFoundException ($ inner , $ id );
77
80
}
78
81
82
+ if ($ decoratedDefinition && $ decoratedDefinition ->isSynthetic ()) {
83
+ throw new InvalidArgumentException (sprintf ('A synthetic service cannot be decorated: service "%s" cannot decorate "%s". ' , $ id , $ inner ));
84
+ }
85
+
79
86
if (isset ($ decoratingDefinitions [$ inner ])) {
80
87
$ decoratingDefinition = $ decoratingDefinitions [$ inner ];
81
88
0 commit comments