@@ -1108,22 +1108,32 @@ protected function resolvePrimitive(ReflectionParameter $parameter)
1108
1108
*/
1109
1109
protected function resolveClass (ReflectionParameter $ parameter )
1110
1110
{
1111
+ $ className = Util::getParameterClassName ($ parameter );
1112
+
1113
+ // First, we check if the dependency has been explicitly bound in
1114
+ // the container, and if so, we resolve it directly from there
1115
+ // to respect explicit bindings over developer set defaults.
1116
+ if ($ this ->bound ($ className )) {
1117
+ return $ this ->make ($ className );
1118
+ }
1119
+
1120
+ // If no binding exists, we check if any default value is
1121
+ // available and return it. This avoids overriding any
1122
+ // developer set defaults when constructing classes.
1123
+ if ($ parameter ->isDefaultValueAvailable ()) {
1124
+ return $ parameter ->getDefaultValue ();
1125
+ }
1126
+
1111
1127
try {
1112
1128
return $ parameter ->isVariadic ()
1113
1129
? $ this ->resolveVariadicClass ($ parameter )
1114
- : $ this ->make (Util:: getParameterClassName ( $ parameter ) );
1130
+ : $ this ->make ($ className );
1115
1131
}
1116
1132
1117
- // If we can not resolve the class instance, we will check to see if the value
1118
- // is optional , and if it is we will return the optional parameter value as
1119
- // the value of the dependency, similarly to how we do this with scalars.
1133
+ // If we can not resolve the class instance, we will check to see if the
1134
+ // value is variadic , and if it is we will return an empty array as the
1135
+ // value of the dependency, similarly to how we do this with scalars.
1120
1136
catch (BindingResolutionException $ e ) {
1121
- if ($ parameter ->isDefaultValueAvailable ()) {
1122
- array_pop ($ this ->with );
1123
-
1124
- return $ parameter ->getDefaultValue ();
1125
- }
1126
-
1127
1137
if ($ parameter ->isVariadic ()) {
1128
1138
array_pop ($ this ->with );
1129
1139
0 commit comments