File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ final class MemoizingContainer implements Container
1111 /** @var array<string, mixed> */
1212 private array $ servicesByType = [];
1313
14+ /** @var array<string, mixed> */
15+ private array $ servicesByName = [];
16+
1417 public function __construct (
1518 #[AutowiredParameter(ref: '@PHPStan\DependencyInjection\Nette\NetteContainer ' )]
1619 private Container $ originalContainer ,
@@ -25,7 +28,14 @@ public function hasService(string $serviceName): bool
2528
2629 public function getService (string $ serviceName )
2730 {
28- return $ this ->originalContainer ->getService ($ serviceName );
31+ if (array_key_exists ($ serviceName , $ this ->servicesByName )) {
32+ return $ this ->servicesByName [$ serviceName ];
33+ }
34+
35+ $ service = $ this ->originalContainer ->getService ($ serviceName );
36+ $ this ->servicesByName [$ serviceName ] = $ service ;
37+
38+ return $ service ;
2939 }
3040
3141 public function getByType (string $ className )
You can’t perform that action at this time.
0 commit comments