@@ -71,7 +71,7 @@ public function createInstance($class)
7171 $ constructorParams [] = $ arg ->getDefaultValue ();
7272 } else {
7373 $ extendedMessage = sprintf ('%s [Required in %s constructor] ' , $ e ->getMessage (), $ class );
74- throw new MissingDependencyException ($ extendedMessage , null , $ e );
74+ throw new MissingDependencyException ($ extendedMessage , 0 , $ e );
7575 }
7676 }
7777 } elseif ($ arg ->isDefaultValueAvailable ()) {
@@ -89,7 +89,7 @@ public function createInstance($class)
8989 return $ instance ;
9090 }
9191
92- public function registerService (string $ implementation , string $ interface = null )
92+ public function registerService ($ implementation , string $ interface = null )
9393 {
9494 $ interface = $ interface ?: $ implementation ;
9595 if (isset ($ this ->serviceMap [$ interface ])) {
@@ -116,6 +116,10 @@ public function getService(string $type)
116116 $ this ->loggerHelper ->logLazyLoading ($ type , $ service );
117117 $ service = $ this ->createInstance ($ service );
118118 $ this ->setService ($ type , $ service );
119+ } elseif ($ service instanceof CallableBeanContainer) {
120+ $ this ->loggerHelper ->logLazyLoading ($ type , $ service );
121+ $ service = $ service ();
122+ $ this ->setService ($ type , $ service );
119123 }
120124
121125 return $ service ;
@@ -129,7 +133,8 @@ public function hasImplementation(string $interface): bool
129133 public function merge (
130134 array $ components ,
131135 string $ instancesKey = InjectorBuilder::INSTANCES_KEY ,
132- string $ registerKey = InjectorBuilder::REGISTER_KEY
136+ string $ registerKey = InjectorBuilder::REGISTER_KEY ,
137+ string $ callableKey = InjectorBuilder::CALLABLE_KEY
133138 )
134139 {
135140 $ beansInstances = $ components [$ instancesKey ] ?? [];
@@ -139,13 +144,19 @@ public function merge(
139144 }
140145 $ this ->setService ($ interface , $ instance );
141146 }
147+
142148 $ registeredBeans = $ components [$ registerKey ] ?? [];
143149 foreach ($ registeredBeans as $ interface => $ implementation ) {
144150 if (is_int ($ interface )) {
145151 $ interface = $ implementation ;
146152 }
147153 $ this ->registerService ($ implementation , $ interface );
148154 }
155+
156+ $ callableBeans = $ components [$ callableKey ] ?? [];
157+ foreach ($ callableBeans as $ interface => $ callable ) {
158+ $ this ->registerService (new CallableBeanContainer ($ interface , $ callable , $ this ), $ interface );
159+ }
149160 }
150161
151162 public function allowNullableConstructorArgs (bool $ allow )
@@ -191,6 +202,5 @@ public function useIdAsTypeName(bool $useIdAsTypeName = true)
191202 public function enableLoggerAwareInjection (bool $ enable = true )
192203 {
193204 $ this ->enableLoggerAwareInjection = $ enable ;
194- }
195- }
205+ }}
196206
0 commit comments