File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed
Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,8 @@ public function beforeCompile()
4444
4545 private function updateDefinition (Definitions \ServiceDefinition $ def ): void
4646 {
47- $ class = $ def ->getType ();
47+ $ resolver = new DI \Resolver ($ this ->getContainerBuilder ());
48+ $ class = $ resolver ->resolveEntityType ($ def ->getFactory ()) ?: $ def ->getType ();
4849 $ setups = $ def ->getSetup ();
4950
5051 foreach (self ::getInjectProperties ($ class ) as $ property => $ type ) {
@@ -61,7 +62,7 @@ private function updateDefinition(Definitions\ServiceDefinition $def): void
6162 array_unshift ($ setups , $ inject );
6263 }
6364
64- foreach (array_reverse (self ::getInjectMethods ($ def -> getType () )) as $ method ) {
65+ foreach (array_reverse (self ::getInjectMethods ($ class )) as $ method ) {
6566 $ inject = new Definitions \Statement ($ method );
6667 foreach ($ setups as $ key => $ setup ) {
6768 if ($ setup ->getEntity () === $ inject ->getEntity ()) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Test: Nette\DI\Compiler: inject.
5+ */
6+
7+ declare (strict_types=1 );
8+
9+ use Nette \DI ;
10+ use Nette \DI \Definitions \Reference ;
11+ use Nette \DI \Definitions \Statement ;
12+ use Tester \Assert ;
13+
14+
15+ require __DIR__ . '/../bootstrap.php ' ;
16+
17+
18+ interface IService
19+ {
20+ }
21+
22+ class Service implements IService
23+ {
24+ public $ foo ;
25+
26+ public function injectFoo (stdClass $ foo )
27+ {
28+ $ this ->foo = $ foo ;
29+ }
30+ }
31+
32+
33+ $ compiler = new DI \Compiler ;
34+ $ compiler ->addExtension ('inject ' , new Nette \DI \Extensions \InjectExtension );
35+ $ container = createContainer ($ compiler , '
36+ services:
37+ one:
38+ type: IService
39+ factory: Service
40+ inject: true
41+ ' );
42+
43+
44+ $ builder = $ compiler ->getContainerBuilder ();
45+
46+ Assert::equal ([
47+ new Statement ([new Reference ('self ' ), 'injectFoo ' ]),
48+ ], $ builder ->getDefinition ('one ' )->getSetup ());
You can’t perform that action at this time.
0 commit comments