@@ -522,46 +522,6 @@ public function setShared($name, $flag)
522
522
throw ContainerModificationsNotAllowedException::fromExistingService ($ name );
523
523
}
524
524
525
- /**
526
- * Instantiate initializers for to avoid checks during service construction.
527
- *
528
- * @param string[]|Initializer\InitializerInterface[]|callable[] $initializers
529
- *
530
- * @return void
531
- */
532
- private function resolveInitializer ($ initializer )
533
- {
534
- if (is_string ($ initializer ) && class_exists ($ initializer )) {
535
- $ initializer = new $ initializer ();
536
- }
537
-
538
- if (is_callable ($ initializer )) {
539
- $ this ->initializers [] = $ initializer ;
540
- return ;
541
- }
542
-
543
- // Error condition; let's find out why.
544
-
545
- if (is_string ($ initializer )) {
546
- throw new InvalidArgumentException (sprintf (
547
- 'An invalid initializer was registered; resolved to class or function "%s" '
548
- . 'which does not exist; please provide a valid function name or class '
549
- . 'name resolving to an implementation of %s ' ,
550
- $ initializer ,
551
- Initializer \InitializerInterface::class
552
- ));
553
- }
554
-
555
- // Otherwise, we have an invalid type.
556
- throw new InvalidArgumentException (sprintf (
557
- 'An invalid initializer was registered. Expected a callable, or an instance of '
558
- . '(or string class name resolving to) "%s", '
559
- . 'but "%s" was received ' ,
560
- Initializer \InitializerInterface::class,
561
- (is_object ($ initializer ) ? get_class ($ initializer ) : gettype ($ initializer ))
562
- ));
563
- }
564
-
565
525
/**
566
526
* Instantiate initializers for to avoid checks during service construction.
567
527
*
@@ -572,7 +532,16 @@ private function resolveInitializer($initializer)
572
532
private function resolveInitializers (array $ initializers )
573
533
{
574
534
foreach ($ initializers as $ initializer ) {
575
- $ this ->resolveInitializer ($ initializer );
535
+ if (is_string ($ initializer ) && class_exists ($ initializer )) {
536
+ $ initializer = new $ initializer ();
537
+ }
538
+
539
+ if (is_callable ($ initializer )) {
540
+ $ this ->initializers [] = $ initializer ;
541
+ return ;
542
+ }
543
+
544
+ throw InvalidArgumentException::fromInvalidInitializer ($ initializer );
576
545
}
577
546
}
578
547
@@ -947,25 +916,6 @@ private function resolveAbstractFactoryInstance($abstractFactory)
947
916
return ;
948
917
}
949
918
950
- // Error condition; let's find out why.
951
-
952
- // If we still have a string, we have a class name that does not resolve
953
- if (is_string ($ abstractFactory )) {
954
- throw new InvalidArgumentException (sprintf (
955
- 'An invalid abstract factory was registered; resolved to class "%s" '
956
- . 'which does not exist; please provide a valid class name resolving '
957
- . 'to an implementation of %s ' ,
958
- $ abstractFactory ,
959
- AbstractFactoryInterface::class
960
- ));
961
- }
962
-
963
- // Otherwise, we have an invalid type.
964
- throw new InvalidArgumentException (sprintf (
965
- 'An invalid abstract factory was registered. Expected an instance of "%s", '
966
- . 'but "%s" was received ' ,
967
- AbstractFactoryInterface::class,
968
- (is_object ($ abstractFactory ) ? get_class ($ abstractFactory ) : gettype ($ abstractFactory ))
969
- ));
919
+ throw InvalidArgumentException::fromInvalidAbstractFactory ($ abstractFactory );
970
920
}
971
921
}
0 commit comments