3
3
namespace Illuminate \Routing ;
4
4
5
5
use Illuminate \Container \Util ;
6
- use Illuminate \Contracts \Container \BindingResolutionException ;
7
6
use Illuminate \Support \Arr ;
8
7
use Illuminate \Support \Reflector ;
9
8
use ReflectionClass ;
10
- use ReflectionException ;
11
9
use ReflectionFunctionAbstract ;
12
10
use ReflectionMethod ;
13
11
use ReflectionParameter ;
@@ -49,24 +47,15 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA
49
47
50
48
$ skippableValue = new stdClass ;
51
49
52
- $ resolvedInterfaces = [];
53
-
54
50
foreach ($ reflector ->getParameters () as $ key => $ parameter ) {
55
- $ className = Reflector::getParameterClassName ($ parameter );
56
-
57
- $ instance = $ this ->transformDependency ($ parameter , $ parameters , $ className , $ skippableValue , $ resolvedInterfaces );
58
-
59
- if ($ instance !== $ skippableValue &&
60
- ! $ this ->alreadyInResolvedInterfaces ($ className , $ resolvedInterfaces )) {
61
- $ resolvedInterfaces [] = $ className ;
62
- }
51
+ $ instance = $ this ->transformDependency ($ parameter , $ parameters , $ skippableValue );
63
52
64
53
if ($ instance !== $ skippableValue ) {
65
54
$ instanceCount ++;
66
55
67
56
$ this ->spliceIntoParameters ($ parameters , $ key , $ instance );
68
57
} elseif (! isset ($ values [$ key - $ instanceCount ]) &&
69
- $ parameter ->isDefaultValueAvailable ()) {
58
+ $ parameter ->isDefaultValueAvailable ()) {
70
59
$ this ->spliceIntoParameters ($ parameters , $ key , $ parameter ->getDefaultValue ());
71
60
}
72
61
@@ -79,27 +68,18 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA
79
68
/**
80
69
* Attempt to transform the given parameter into a class instance.
81
70
*
82
- * @param ReflectionParameter $parameter
71
+ * @param \ ReflectionParameter $parameter
83
72
* @param array $parameters
84
- * @param string $className
85
73
* @param object $skippableValue
86
- * @param $resolvedInterfaces
87
74
* @return mixed
88
- *
89
- * @throws BindingResolutionException
90
- * @throws ReflectionException
91
75
*/
92
- protected function transformDependency (ReflectionParameter $ parameter , $ parameters , $ className , object $ skippableValue, $ resolvedInterfaces )
76
+ protected function transformDependency (ReflectionParameter $ parameter , $ parameters , $ skippableValue )
93
77
{
94
78
if ($ attribute = Util::getContextualAttributeFromDependency ($ parameter )) {
95
79
return $ this ->container ->resolveFromAttribute ($ attribute );
96
80
}
97
81
98
- if ($ this ->isSimilarConcreteToExistingParameterButDifferentInterface (
99
- $ className , $ parameters , $ resolvedInterfaces
100
- )) {
101
- return $ this ->container ->make ($ className );
102
- }
82
+ $ className = Reflector::getParameterClassName ($ parameter );
103
83
104
84
// If the parameter has a type-hinted class, we will check to see if it is already in
105
85
// the list of parameters. If it is we will just skip it as it is probably a model
@@ -115,24 +95,6 @@ protected function transformDependency(ReflectionParameter $parameter, $paramete
115
95
return $ skippableValue ;
116
96
}
117
97
118
- /**
119
- * Determines if an instance of the given class is already in the parameters, but the route is type-hinting another interface that hasn't yet been resolved.
120
- *
121
- * @param string $className
122
- * @param array $parameters
123
- * @param array $resolvedInterfaces
124
- * @return bool
125
- */
126
- protected function isSimilarConcreteToExistingParameterButDifferentInterface ($ className , array $ parameters , array $ resolvedInterfaces )
127
- {
128
- // See: https://github.com/laravel/framework/pull/53275
129
- return $ className &&
130
- $ this ->alreadyInParameters ($ className , $ parameters ) &&
131
- interface_exists ($ className ) &&
132
- ! $ this ->alreadyInResolvedInterfaces ($ className , $ resolvedInterfaces ) &&
133
- (new ReflectionClass ($ className ))->isInterface ();
134
- }
135
-
136
98
/**
137
99
* Determine if an object of the given class is in a list of parameters.
138
100
*
@@ -145,22 +107,6 @@ protected function alreadyInParameters($class, array $parameters)
145
107
return ! is_null (Arr::first ($ parameters , fn ($ value ) => $ value instanceof $ class ));
146
108
}
147
109
148
- /**
149
- * Determine if the given class name is already in the list of resolved interfaces.
150
- *
151
- * @param string|null $class
152
- * @param array $resolvedInterfaces
153
- * @return bool
154
- */
155
- protected function alreadyInResolvedInterfaces ($ class , array $ resolvedInterfaces )
156
- {
157
- if (! is_null ($ class )) {
158
- return in_array ($ class , $ resolvedInterfaces );
159
- }
160
-
161
- return false ;
162
- }
163
-
164
110
/**
165
111
* Splice the given value into the parameter list.
166
112
*
0 commit comments