File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -348,7 +348,7 @@ protected function getDependencies($parameters)
348348 }
349349 else
350350 {
351- $ dependencies [] = $ this ->make ( $ dependency -> name );
351+ $ dependencies [] = $ this ->resolveClass ( $ parameter );
352352 }
353353 }
354354
@@ -375,6 +375,35 @@ protected function resolveNonClass(ReflectionParameter $parameter)
375375 }
376376 }
377377
378+ /**
379+ * Resolve a class based dependency from the container.
380+ *
381+ * @param \ReflectionParameter $parameter
382+ * @return mixed
383+ */
384+ protected function resolveClass (ReflectionParameter $ parameter )
385+ {
386+ try
387+ {
388+ return $ this ->make ($ parameter ->getClass ()->name );
389+ }
390+
391+ // If we can not resolve the class instance, we will check to see if the value
392+ // is optional, and if it is we will return the optional parameter value as
393+ // the value of the dependency, similarly to how we do this with scalars.
394+ catch (BindingResolutionException $ e )
395+ {
396+ if ($ parameter ->isOptional ())
397+ {
398+ return $ parameter ->getDefaultValue ();
399+ }
400+ else
401+ {
402+ throw $ e ;
403+ }
404+ }
405+ }
406+
378407 /**
379408 * Register a new resolving callback.
380409 *
Original file line number Diff line number Diff line change 2626 {"message" : " Restore method on Eloquent models now fires restoring and restored events." , "backport" : null },
2727 {"message" : " Fixed re-population of radio buttons and checkboxes in FormBuilder." , "backport" : null },
2828 {"message" : " Postgres ENUMs are now more truly implemented using 'check' constraints." , "backport" : null },
29- {"message" : " Added selectMonth and selectYear to FormBuilder." , "backport" : null }
29+ {"message" : " Added selectMonth and selectYear to FormBuilder." , "backport" : null },
30+ {"message" : " Fix container resolution of default values for non-scalar dependencies." , "backport" : null }
3031 ]
3132}
You can’t perform that action at this time.
0 commit comments