Maybe I am not understanding correctly, but if so i have a fix. I have a route /dragon and i want to add it to a group starting with a locale like en_GB, after which the route would become /en_GB/dragon. However, calling setParentGroup($group) has no effect.
$request = ServerRequestFactory::fromGlobals(
$_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
);
$router = new Router();
// create a group the normal way
$group = $router->group('/en_GB', function (\League\Route\RouteGroup $route) {
$route->map('GET', '/yes', function (ServerRequestInterface $request) : ResponseInterface {
$response = new Response;
$response->getBody()->write('<h1>YES</h1>');
return $response;
});
});
// create a non grouped route
$route = $router->map('GET', '/dragon', function (ServerRequestInterface $request) : ResponseInterface {
$response = new Response;
$response->getBody()->write('<h1>Here be Dragons!</h1>');
return $response;
});
// add the route to the group
$route->setParentGroup($group);
// get the response
$response = $router->dispatch($request);
I can send a pull reuest if indeed this behaviour is incorrect:
/**
* Set the parent group
*
* @param \League\Route\RouteGroup $group
*
* @return \League\Route\Route
*/
public function setParentGroup(RouteGroup $group) : self
{
$this->group = $group;
$prefix = $group->getPrefix();
$path = $this->getPath();
if (strcmp($prefix, substr($path, 0, strlen($prefix))) != 0) {
$path = $prefix . $path;
$this->path = $path;
}
return $this;
}
Maybe I am not understanding correctly, but if so i have a fix. I have a route
/dragon
and i want to add it to a group starting with a locale likeen_GB
, after which the route would become/en_GB/dragon
. However, callingsetParentGroup($group)
has no effect.route expected actual /en_GB/yes 200 200 /dragon 404 200 /en_GB/dragon 200 404
I can send a pull reuest if indeed this behaviour is incorrect:
After which the expected routes now work.