@@ -30,16 +30,10 @@ public function __construct(string $configPath)
3030
3131 $ config = require $ configPath ;
3232 foreach ($ config ['container ' ]['singletons ' ] ?? [] as $ id => $ service ) {
33- if ($ service instanceof \Closure || \is_string ($ service )) {
34- $ returnType = (new \ReflectionFunction ($ service ))->getReturnType ();
35- if (!$ returnType instanceof \ReflectionNamedType) {
36- throw new \RuntimeException (sprintf ('Please provide return type for %s service closure ' , $ id ));
37- }
38-
39- $ this ->services [$ id ] = $ returnType ->getName ();
40- } else {
41- $ this ->services [$ id ] = $ service ['class ' ] ?? $ service [0 ]['class ' ];
42- }
33+ $ this ->addServiceDefinition ($ id , $ service );
34+ }
35+ foreach ($ config ['container ' ]['definitions ' ] ?? [] as $ id => $ service ) {
36+ $ this ->addServiceDefinition ($ id , $ service );
4337 }
4438
4539 foreach ($ config ['components ' ] ?? [] as $ id => $ component ) {
@@ -52,10 +46,6 @@ public function __construct(string $configPath)
5246 throw new \RuntimeException (sprintf ('Invalid value for component with id %s. Expected object or array. ' , $ id ));
5347 }
5448
55- if (null !== $ identityClass = $ component ['identityClass ' ] ?? null ) {
56- $ this ->components [$ id ]['identityClass ' ] = $ identityClass ;
57- }
58-
5949 if (null !== $ class = $ component ['class ' ] ?? null ) {
6050 $ this ->components [$ id ]['class ' ] = $ class ;
6151 }
@@ -81,8 +71,22 @@ public function getComponentClassById(string $id): ?string
8171 return $ this ->components [$ id ]['class ' ] ?? null ;
8272 }
8373
84- public function getComponentIdentityClassById (string $ id ): ?string
74+ /**
75+ * @param string|\Closure|array<mixed> $service
76+ *
77+ * @throws \ReflectionException
78+ */
79+ private function addServiceDefinition (string $ id , $ service ): void
8580 {
86- return $ this ->components [$ id ]['identityClass ' ] ?? null ;
81+ if ($ service instanceof \Closure || \is_string ($ service )) {
82+ $ returnType = (new \ReflectionFunction ($ service ))->getReturnType ();
83+ if (!$ returnType instanceof \ReflectionNamedType) {
84+ throw new \RuntimeException (sprintf ('Please provide return type for %s service closure ' , $ id ));
85+ }
86+
87+ $ this ->services [$ id ] = $ returnType ->getName ();
88+ } else {
89+ $ this ->services [$ id ] = $ service ['class ' ] ?? $ service [0 ]['class ' ];
90+ }
8791 }
8892}
0 commit comments