File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
src/Symfony/Component/DependencyInjection Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \DependencyInjection \Compiler ;
13
13
14
14
use Symfony \Component \DependencyInjection \Alias ;
15
+ use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
15
16
use Symfony \Component \DependencyInjection \Reference ;
16
17
use Symfony \Component \DependencyInjection \ContainerBuilder ;
17
18
@@ -84,7 +85,12 @@ private function processArguments(array $arguments)
84
85
*/
85
86
private function getDefinitionId ($ id )
86
87
{
88
+ $ seen = array ();
87
89
while ($ this ->container ->hasAlias ($ id )) {
90
+ if (isset ($ seen [$ id ])) {
91
+ throw new ServiceCircularReferenceException ($ id , array_keys ($ seen ));
92
+ }
93
+ $ seen [$ id ] = true ;
88
94
$ id = (string ) $ this ->container ->getAlias ($ id );
89
95
}
90
96
Original file line number Diff line number Diff line change @@ -48,6 +48,17 @@ public function testProcessRecursively()
48
48
$ this ->assertEquals ('foo ' , (string ) $ arguments [0 ]);
49
49
}
50
50
51
+ /**
52
+ * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
53
+ */
54
+ public function testAliasCircularReference ()
55
+ {
56
+ $ container = new ContainerBuilder ();
57
+ $ container ->setAlias ('bar ' , 'foo ' );
58
+ $ container ->setAlias ('foo ' , 'bar ' );
59
+ $ this ->process ($ container );
60
+ }
61
+
51
62
protected function process (ContainerBuilder $ container )
52
63
{
53
64
$ pass = new ResolveReferencesToAliasesPass ();
You can’t perform that action at this time.
0 commit comments