File tree 2 files changed +28
-0
lines changed
src/Symfony/Component/De
8000
pendencyInjection
2 files changed +28
-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 \Definition ;
15
16
use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
16
17
use Symfony \Component \DependencyInjection \Reference ;
17
18
use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -42,6 +43,7 @@ public function process(ContainerBuilder $container)
42
43
$ definition ->setArguments ($ this ->processArguments ($ definition ->getArguments ()));
43
44
$ definition ->setMethodCalls ($ this ->processArguments ($ definition ->getMethodCalls ()));
44
45
$ definition ->setProperties ($ this ->processArguments ($ definition ->getProperties ()));
46
+ $ definition ->setFactoryService ($ this ->processFactoryService ($ definition ->getFactoryService ()));
45
47
}
46
48
47
49
foreach ($ container ->getAliases () as $ id => $ alias ) {
@@ -76,6 +78,15 @@ private function processArguments(array $arguments)
76
78
return $ arguments ;
77
79
}
78
80
81
+ private function processFactoryService ($ factoryService )
82
+ {
83
+ if (null === $ factoryService ) {
84
+ return ;
85
+ }
86
+
87
+ return $ this ->getDefinitionId ($ factoryService );
88
+ }
89
+
79
90
/**
80
91
* Resolves an alias into a definition id.
81
92
*
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \DependencyInjection \Tests \Compiler ;
13
13
14
+ use Symfony \Component \DependencyInjection \Alias ;
15
+ use Symfony \Component \DependencyInjection \Definition ;
14
16
use Symfony \Component \DependencyInjection \Reference ;
15
17
use Symfony \Component \DependencyInjection \Compiler \ResolveReferencesToAliasesPass ;
16
18
use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -59,6 +61,21 @@ public function testAliasCircularReference()
59
61
$ this ->process ($ container );
60
62
}
61
63
64
+ public function testResolveFactory ()
65
+ {
66
+ $ container = new ContainerBuilder ();
67
+ $ container ->register ('factory ' , 'Factory ' );
68
+ $ container ->setAlias ('factory_alias ' , new Alias ('factory ' ));
69
+ $ foo = new Definition ();
70
+ $ foo ->setFactoryService ('factory_alias ' );
71
+ $ foo ->setFactoryMethod ('createFoo ' );
72
+ $ container ->setDefinition ('foo ' , $ foo );
73
+
74
+ $ this ->process ($ container );
75
+
76
+ $ this ->assertSame ('factory ' , $ foo ->getFactoryService ());
77
+ }
78
+
62
79
protected function process (ContainerBuilder $ container )
63
80
{
64
81
$ pass = new ResolveReferencesToAliasesPass ();
You can’t perform that action at this time.