@@ -274,11 +274,25 @@ protected function configure(array $config)
274
274
continue ;
275
275
}
276
276
277
+ // Error condition; let's find out why.
278
+
279
+ // If we still have a string, we have a class name that does not resolve
280
+ if (is_string ($ abstractFactory )) {
281
+ throw new InvalidArgumentException (sprintf (
282
+ 'An invalid abstract factory was registered; resolved to class "%s" '
283
+ . 'which does not exist; please provide a valid class name resolving '
284
+ . 'to an implementation of %s ' ,
285
+ $ abstractFactory ,
286
+ AbstractFactoryInterface::class
287
+ ));
288
+ }
289
+
290
+ // Otherwise, we have an invalid type.
277
291
throw new InvalidArgumentException (sprintf (
278
- 'An invalid abstract factory was registered. An instance of "%s" was expected , '
292
+ 'An invalid abstract factory was registered. Expected an instance of "%s", '
279
293
. 'but "%s" was received ' ,
280
294
AbstractFactoryInterface::class,
281
- is_object ($ abstractFactory ) ? get_class ($ abstractFactory ) : gettype ($ abstractFactory )
295
+ ( is_object ($ abstractFactory ) ? get_class ($ abstractFactory ) : gettype ($ abstractFactory) )
282
296
));
283
297
}
284
298
}
@@ -294,11 +308,25 @@ protected function configure(array $config)
294
308
continue ;
295
309
}
296
310
311
+ // Error condition; let's find out why.
312
+
313
+ if (is_string ($ initializer )) {
314
+ throw new InvalidArgumentException (sprintf (
315
+ 'An invalid initializer was registered; resolved to class or function "%s" '
316
+ . 'which does not exist; please provide a valid function name or class '
317
+ . 'name resolving to an implementation of %s ' ,
318
+ $ initializer ,
319
+ InitializerInterface::class
320
+ ));
321
+ }
322
+
323
+ // Otherwise, we have an invalid type.
297
324
throw new InvalidArgumentException (sprintf (
298
- 'An invalid initializer was registered. A callable or an instance of "%s" was expected, but
299
- "%s" was received ' ,
325
+ 'An invalid initializer was registered. Expected a callable, or an instance of '
326
+ . '(or string class name resolving to) "%s", '
327
+ . 'but "%s" was received ' ,
300
328
InitializerInterface::class,
301
- is_object ($ initializer ) ? get_class ($ initializer ) : gettype ($ initializer )
329
+ ( is_object ($ initializer ) ? get_class ($ initializer ) : gettype ($ initializer) )
302
330
));
303
331
}
304
332
}
@@ -391,20 +419,21 @@ private function createDelegatorFromName($name, array $options = null)
391
419
$ delegatorFactory = $ this ->createLazyServiceDelegatorFactory ();
392
420
}
393
421
394
- if (is_string ($ delegatorFactory ) && ! class_exists ($ delegatorFactory )) {
395
- throw new ServiceNotCreatedException (sprintf (
396
- 'An invalid delegator was provided. A callable or an instance of "%s" was expected, '
397
- . 'but "%s" was received ' ,
398
- DelegatorFactoryInterface::class,
399
- $ delegatorFactory
400
- ));
401
- }
402
-
403
- if (is_string ($ delegatorFactory )) {
404
- $ delegatorFactory = $ this ->delegators [$ name ][$ index ] = new $ delegatorFactory ();
422
+ if (is_string ($ delegatorFactory ) && class_exists ($ delegatorFactory )) {
423
+ $ delegatorFactory = new $ delegatorFactory ();
405
424
}
406
425
407
426
if (! is_callable ($ delegatorFactory )) {
427
+ if (is_string ($ delegatorFactory )) {
428
+ throw new ServiceNotCreatedException (sprintf (
429
+ 'An invalid delegator factory was registered; resolved to class or function "%s" '
430
+ . 'which does not exist; please provide a valid function name or class name resolving '
431
+ . 'to an implementation of %s ' ,
432
+ $ delegatorFactory ,
433
+ DelegatorFactoryInterface::class
434
+ ));
435
+ }
436
+
408
437
throw new ServiceNotCreatedException (sprintf (
409
438
'A non-callable delegator, "%s", was provided; expected a callable or '
410
439
. 'instance of "%s" ' ,
@@ -413,6 +442,8 @@ private function createDelegatorFromName($name, array $options = null)
413
442
));
414
443
}
415
444
445
+ $ this ->delegators [$ name ][$ index ] = $ delegatorFactory ;
446
+
416
447
$ creationCallback = function () use ($ delegatorFactory , $ name , $ creationCallback , $ options ) {
417
448
return $ delegatorFactory ($ this ->creationContext , $ name , $ creationCallback , $ options );
418
449
};
0 commit comments