diff --git a/Slim/Routing/Route.php b/Slim/Routing/Route.php index c4984235b..2cd9fa567 100644 --- a/Slim/Routing/Route.php +++ b/Slim/Routing/Route.php @@ -108,7 +108,7 @@ class Route implements RouteInterface, RequestHandlerInterface * @param CallableResolverInterface $callableResolver * @param ContainerInterface|null $container * @param InvocationStrategyInterface|null $invocationStrategy - * @param RouteGroup[] $groups The parent route groups + * @param RouteGroupInterface[] $groups The parent route groups * @param int $identifier The route identifier */ public function __construct( diff --git a/Slim/Routing/RouteCollector.php b/Slim/Routing/RouteCollector.php index 4a7428516..61b450300 100644 --- a/Slim/Routing/RouteCollector.php +++ b/Slim/Routing/RouteCollector.php @@ -17,6 +17,7 @@ use Slim\Interfaces\CallableResolverInterface; use Slim\Interfaces\InvocationStrategyInterface; use Slim\Interfaces\RouteCollectorInterface; +use Slim\Interfaces\RouteCollectorProxyInterface; use Slim\Interfaces\RouteGroupInterface; use Slim\Interfaces\RouteInterface; use Slim\Interfaces\RouteParserInterface; @@ -69,7 +70,7 @@ class RouteCollector implements RouteCollectorInterface /** * Route groups * - * @var RouteGroup[] + * @var RouteGroupInterface[] */ protected array $routeGroups = []; @@ -224,15 +225,7 @@ public function lookupRoute(string $identifier): RouteInterface */ public function group(string $pattern, $callable): RouteGroupInterface { - $routeCollectorProxy = new RouteCollectorProxy( - $this->responseFactory, - $this->callableResolver, - $this->container, - $this, - $pattern - ); - - $routeGroup = new RouteGroup($pattern, $callable, $this->callableResolver, $routeCollectorProxy); + $routeGroup = $this->createGroup($pattern, $callable); $this->routeGroups[] = $routeGroup; $routeGroup->collectRoutes(); @@ -241,6 +234,26 @@ public function group(string $pattern, $callable): RouteGroupInterface return $routeGroup; } + /** + * @param string|callable $callable + */ + protected function createGroup(string $pattern, $callable): RouteGroupInterface + { + $routeCollectorProxy = $this->createProxy($pattern); + return new RouteGroup($pattern, $callable, $this->callableResolver, $routeCollectorProxy); + } + + protected function createProxy(string $pattern): RouteCollectorProxyInterface + { + return new RouteCollectorProxy( + $this->responseFactory, + $this->callableResolver, + $this->container, + $this, + $pattern + ); + } + /** * {@inheritdoc} */