@@ -874,9 +874,6 @@ protected function resolveDependencies(array $dependencies)
874874 ? $ this ->resolvePrimitive ($ dependency )
875875 : $ this ->resolveClass ($ dependency );
876876
877- // If this dependency is variadic the result will be an array but they will
878- // need to be unrolled so they look like additional results instead of a
879- // single result representing an array of items.
880877 if ($ dependency ->isVariadic ()) {
881878 $ results = array_merge ($ results , $ result );
882879 } else {
@@ -953,28 +950,9 @@ protected function resolvePrimitive(ReflectionParameter $parameter)
953950 protected function resolveClass (ReflectionParameter $ parameter )
954951 {
955952 try {
956- // The default case is handled early and quickly so more complicated
957- // checks that apply only for variadic calls only run in cases
958- // where the parameter is actually variadic.
959- if (! $ parameter ->isVariadic ()) {
960- return $ this ->make ($ parameter ->getClass ()->name );
961- }
962-
963- $ abstract = $ this ->getAlias ($ parameter ->getClass ()->name );
964- $ concrete = $ this ->getContextualConcrete ($ abstract );
965-
966- // If the concrete for a variadic is not an array we can treat it
967- // like other parameters and will assume making the parameter
968- // will result in an array.
969- if (! is_array ($ concrete )) {
970- return $ this ->make ($ parameter ->getClass ()->name );
971- }
972-
973- // If the concrete for a variadic is an array, we call resolve on
974- // each value in the concrete array.
975- return array_map (function ($ abstract ) {
976- return $ this ->resolve ($ abstract );
977- }, $ concrete );
953+ return $ parameter ->isVariadic ()
954+ ? $ this ->resolveVariadicClass ($ parameter )
955+ : $ this ->make ($ parameter ->getClass ()->name );
978956 }
979957
980958 // If we can not resolve the class instance, we will check to see if the value
@@ -985,11 +963,6 @@ protected function resolveClass(ReflectionParameter $parameter)
985963 return $ parameter ->getDefaultValue ();
986964 }
987965
988- // The "default value" for variadic can never be null but PHP does not
989- // treat these parameters as having a default value. By returning an
990- // empty array for variadic values we can better emulate PHP
991- // runtime which will always result in an empty array if
992- // no values are present.
993966 if ($ parameter ->isVariadic ()) {
994967 return [];
995968 }
@@ -998,6 +971,25 @@ protected function resolveClass(ReflectionParameter $parameter)
998971 }
999972 }
1000973
974+ /**
975+ * Resolve a class based variadic dependency from the container.
976+ *
977+ * @param \ReflectionParameter $parameter
978+ * @return mixed
979+ */
980+ protected function resolveVariadicClass (ReflectionParameter $ parameter )
981+ {
982+ $ abstract = $ this ->getAlias ($ parameter ->getClass ()->name );
983+
984+ if (! is_array ($ concrete = $ this ->getContextualConcrete ($ abstract ))) {
985+ return $ this ->make ($ parameter ->getClass ()->name );
986+ }
987+
988+ return array_map (function ($ abstract ) {
989+ return $ this ->resolve ($ abstract );
990+ }, $ concrete );
991+ }
992+
1001993 /**
1002994 * Throw an exception that the concrete is not instantiable.
1003995 *
0 commit comments