44
55class Injector
66{
7- const A_RAW = ': ' ;
8- const A_DELEGATE = '+ ' ;
9- const A_DEFINE = '@ ' ;
10- const I_BINDINGS = 1 ;
11- const I_DELEGATES = 2 ;
12- const I_PREPARES = 4 ;
13- const I_ALIASES = 8 ;
14- const I_SHARES = 16 ;
15- const I_ALL = 31 ;
16-
17- const E_NON_EMPTY_STRING_ALIAS = 1 ;
18- const M_NON_EMPTY_STRING_ALIAS = "Invalid alias: non-empty string required at arguments 1 and 2 " ;
19- const E_SHARED_CANNOT_ALIAS = 2 ;
20- const M_SHARED_CANNOT_ALIAS = "Cannot alias class %s to %s because it is currently shared " ;
21- const E_SHARE_ARGUMENT = 3 ;
22- const M_SHARE_ARGUMENT = "%s::share() requires a string class name or object instance at Argument 1; %s specified " ;
23- const E_ALIASED_CANNOT_SHARE = 4 ;
24- const M_ALIASED_CANNOT_SHARE = "Cannot share class %s because it is currently aliased to %s " ;
25- const E_INVOKABLE = 5 ;
26- const M_INVOKABLE = "Invalid invokable: callable or provisional string required " ;
27- const E_NON_PUBLIC_CONSTRUCTOR = 6 ;
28- const M_NON_PUBLIC_CONSTRUCTOR = "Cannot instantiate protected/private constructor in class %s " ;
29- const E_NEEDS_DEFINITION = 7 ;
30- const M_NEEDS_DEFINITION = "Injection definition required for %s %s " ;
31- const E_MAKE_FAILURE = 8 ;
32- const M_MAKE_FAILURE = "Could not make %s: %s " ;
33- const E_UNDEFINED_PARAM = 9 ;
34- const M_UNDEFINED_PARAM = "No definition available to provision typeless parameter \$%s at position %d in %s()%s " ;
35- const E_DELEGATE_ARGUMENT = 10 ;
36- const M_DELEGATE_ARGUMENT = "%s::delegate expects a valid callable or executable class::method string at Argument 2%s " ;
37- const E_CYCLIC_DEPENDENCY = 11 ;
38- const M_CYCLIC_DEPENDENCY = "Detected a cyclic dependency while provisioning %s " ;
39- const E_MAKING_FAILED = 12 ;
40- const M_MAKING_FAILED = "Making %s did not result in an object, instead result is of type '%s' " ;
7+ public const A_RAW = ': ' ;
8+ public const A_DELEGATE = '+ ' ;
9+ public const A_DEFINE = '@ ' ;
10+ public const I_BINDINGS = 1 ;
11+ public const I_DELEGATES = 2 ;
12+ public const I_PREPARES = 4 ;
13+ public const I_ALIASES = 8 ;
14+ public const I_SHARES = 16 ;
15+ public const I_ALL = 31 ;
16+
17+ public const E_NON_EMPTY_STRING_ALIAS = 1 ;
18+ public const M_NON_EMPTY_STRING_ALIAS = "Invalid alias: non-empty string required at arguments 1 and 2 " ;
19+ public const E_SHARED_CANNOT_ALIAS = 2 ;
20+ public const M_SHARED_CANNOT_ALIAS = "Cannot alias class %s to %s because it is currently shared " ;
21+ public const E_SHARE_ARGUMENT = 3 ;
22+ public const M_SHARE_ARGUMENT = "%s::share() requires a string class name or object instance at Argument 1; %s specified " ;
23+ public const E_ALIASED_CANNOT_SHARE = 4 ;
24+ public const M_ALIASED_CANNOT_SHARE = "Cannot share class %s because it is currently aliased to %s " ;
25+ public const E_INVOKABLE = 5 ;
26+ public const M_INVOKABLE = "Invalid invokable: callable or provisional string required " ;
27+ public const E_NON_PUBLIC_CONSTRUCTOR = 6 ;
28+ public const M_NON_PUBLIC_CONSTRUCTOR = "Cannot instantiate protected/private constructor in class %s " ;
29+ public const E_NEEDS_DEFINITION = 7 ;
30+ public const M_NEEDS_DEFINITION = "Injection definition required for %s %s " ;
31+ public const E_MAKE_FAILURE = 8 ;
32+ public const M_MAKE_FAILURE = "Could not make %s: %s " ;
33+ public const E_UNDEFINED_PARAM = 9 ;
34+ public const M_UNDEFINED_PARAM = "No definition available to provision typeless parameter \$%s at position %d in %s()%s " ;
35+ public const E_DELEGATE_ARGUMENT = 10 ;
36+ public const M_DELEGATE_ARGUMENT = "%s::delegate expects a valid callable or executable class::method string at Argument 2%s " ;
37+ public const E_CYCLIC_DEPENDENCY = 11 ;
38+ public const M_CYCLIC_DEPENDENCY = "Detected a cyclic dependency while provisioning %s " ;
39+ public const E_MAKING_FAILED = 12 ;
40+ public const M_MAKING_FAILED = "Making %s did not result in an object, instead result is of type '%s' " ;
4141
4242 private $ reflector ;
4343 private $ classDefinitions = array ();
@@ -50,7 +50,7 @@ class Injector
5050
5151 public function __construct (?Reflector $ reflector = null )
5252 {
53- $ this ->reflector = $ reflector ?: new CachingReflector ;
53+ $ this ->reflector = $ reflector ?: new CachingReflector () ;
5454 }
5555
5656 public function __clone ()
@@ -141,7 +141,7 @@ public function alias($original, $alias)
141141
142142 private function normalizeName ($ className )
143143 {
144- return ltrim (strtolower ($ className ), '\\' );
144+ return ltrim (strtolower ($ className ), '\\? ' );
145145 }
146146
147147 /**
@@ -380,12 +380,7 @@ public function make($name, array $args = array())
380380 }
381381
382382 unset($ this ->inProgressMakes [$ normalizedClass ]);
383- }
384- catch (\Throwable $ exception ) {
385- unset($ this ->inProgressMakes [$ normalizedClass ]);
386- throw $ exception ;
387- }
388- catch (\Exception $ exception ) {
383+ } catch (\Throwable $ exception ) {
389384 unset($ this ->inProgressMakes [$ normalizedClass ]);
390385 throw $ exception ;
391386 }
@@ -441,7 +436,7 @@ private function instantiateWithoutCtorParams($className)
441436 );
442437 }
443438
444- return new $ className ;
439+ return new $ className() ;
445440 }
446441
447442 private function provisionFuncArgs (\ReflectionFunctionAbstract $ reflFunc , array $ definition , ?array $ reflParams = null , $ className = null )
@@ -593,7 +588,11 @@ private function prepareInstance($obj, $normalizedClass)
593588 }
594589 }
595590
596- $ interfaces = @class_implements ($ obj );
591+ if ($ obj !== null ) {
592+ $ interfaces = @class_implements ($ obj );
593+ } else {
594+ $ interfaces = false ;
595+ }
597596
598597 if ($ interfaces === false ) {
599598 throw new InjectionException (
0 commit comments