@@ -583,9 +583,30 @@ public function mergeWithLastGroup($new)
583583 */
584584 public static function mergeGroup ($ new , $ old )
585585 {
586+ $ new ['namespace ' ] = static ::formatUsesPrefix ($ new , $ old );
587+
586588 $ new ['prefix ' ] = static ::formatGroupPrefix ($ new , $ old );
587589
588- return array_merge_recursive (array_except ($ old , array ('prefix ' , 'domain ' )), $ new );
590+ return array_merge_recursive (array_except ($ old , array ('namespace ' , 'prefix ' , 'domain ' )), $ new );
591+ }
592+
593+ /**
594+ * Format the uses prefix for the new group attributes.
595+ *
596+ * @param array $new
597+ * @param array $old
598+ * @return string
599+ */
600+ protected static function formatUsesPrefix ($ new , $ old )
601+ {
602+ if (isset ($ new ['namespace ' ]))
603+ {
604+ return trim (array_get ($ old , 'namespace ' ), '\\' ).'\\' .trim ($ new ['namespace ' ], '\\' );
605+ }
606+ else
607+ {
608+ return array_get ($ old , 'namespace ' );
609+ }
589610 }
590611
591612 /**
@@ -716,9 +737,22 @@ protected function getControllerAction($action)
716737 {
717738 if (is_string ($ action )) $ action = array ('uses ' => $ action );
718739
740+ // Here we'll get an instance of this controller dispatcher and hand it off to
741+ // the Closure so it will be used to resolve the class instances out of our
742+ // IoC container instance and call the appropriate methods on the class.
743+ if (count ($ this ->groupStack ) > 0 )
744+ {
745+ $ action ['uses ' ] = $ this ->prependGroupUses ($ action ['uses ' ]);
746+ }
747+
748+ // Here we'll get an instance of this controller dispatcher and hand it off to
749+ // the Closure so it will be used to resolve the class instances out of our
750+ // IoC container instance and call the appropriate methods on the class.
719751 $ action ['controller ' ] = $ action ['uses ' ];
720752
721- return array_set ($ action , 'uses ' , $ this ->getClassClosure ($ action ['uses ' ]));
753+ $ closure = $ this ->getClassClosure ($ action ['uses ' ]);
754+
755+ return array_set ($ action , 'uses ' , $ closure );
722756 }
723757
724758 /**
@@ -751,6 +785,19 @@ protected function getClassClosure($controller)
751785 };
752786 }
753787
788+ /**
789+ * Prepend the last group uses onto the use clause.
790+ *
791+ * @param string $uses
792+ * @return string
793+ */
794+ protected function prependGroupUses ($ uses )
795+ {
796+ $ group = last ($ this ->groupStack );
797+
798+ return isset ($ group ['namespace ' ]) ? $ group ['namespace ' ].'\\' .$ uses : $ uses ;
799+ }
800+
754801 /**
755802 * Dispatch the request to the application.
756803 *
0 commit comments