1
0
mirror of https://github.com/flarum/core.git synced 2025-07-21 08:41:17 +02:00

Require unique route names (#2771)

This commit is contained in:
Sami Mazouz
2021-04-10 20:38:25 +01:00
committed by GitHub
parent 68f0dc4d4c
commit 598bb94657
4 changed files with 20 additions and 22 deletions

View File

@@ -73,34 +73,32 @@ class RouteCollection
public function addRoute($method, $path, $name, $handler)
{
if (isset($this->routes[$method][$name])) {
throw new \RuntimeException("Route $name on method $method already exists");
if (isset($this->routes[$name])) {
throw new \RuntimeException("Route $name already exists");
}
$this->routes[$method][$name] = $this->pendingRoutes[$method][$name] = compact('path', 'handler');
$this->routes[$name] = $this->pendingRoutes[$name] = compact('method', 'path', 'handler');
return $this;
}
public function removeRoute(string $method, string $name): self
public function removeRoute(string $name): self
{
unset($this->routes[$method][$name], $this->pendingRoutes[$method][$name]);
unset($this->routes[$name], $this->pendingRoutes[$name]);
return $this;
}
protected function applyRoutes(): void
{
foreach ($this->pendingRoutes as $method => $routes) {
foreach ($routes as $name => $route) {
$routeDatas = $this->routeParser->parse($route['path']);
foreach ($this->pendingRoutes as $name => $route) {
$routeDatas = $this->routeParser->parse($route['path']);
foreach ($routeDatas as $routeData) {
$this->dataGenerator->addRoute($method, $routeData, ['name' => $name, 'handler' => $route['handler']]);
}
$this->reverse[$name] = $routeDatas;
foreach ($routeDatas as $routeData) {
$this->dataGenerator->addRoute($route['method'], $routeData, ['name' => $name, 'handler' => $route['handler']]);
}
$this->reverse[$name] = $routeDatas;
}
$this->pendingRoutes = [];