Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New ability to override RouteGroupInterface in the Route class #3245

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Slim/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 23 additions & 10 deletions Slim/Routing/RouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +70,7 @@ class RouteCollector implements RouteCollectorInterface
/**
* Route groups
*
* @var RouteGroup[]
* @var RouteGroupInterface[]
*/
protected array $routeGroups = [];

Expand Down Expand Up @@ -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();
Expand All @@ -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}
*/
Expand Down