Skip to content

Commit

Permalink
refactor: extract protectDefinedCliRoutes() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 10, 2022
1 parent b9b9cfc commit 6a39da0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ public function getRoute(string $uri): array
);

// Ensure routes registered via $routes->cli() are not accessible via web.
$this->protectDefinedCliRoutes();

// Check _remao()
$this->checkRemap();

// Check parameters
try {
$this->checkParameters($uri);
} catch (ReflectionException $e) {
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
}

return [$this->directory, $this->controller, $this->method, $this->params];
}

private function protectDefinedCliRoutes()
{
if ($this->httpVerb !== 'cli') {
$controller = strtolower($this->controller);
$methodName = strtolower($this->method);
Expand All @@ -186,18 +203,6 @@ public function getRoute(string $uri): array
}
}
}

// Check _remao()
$this->checkRemap();

// Check parameters
try {
$this->checkParameters($uri);
} catch (ReflectionException $e) {
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
}

return [$this->directory, $this->controller, $this->method, $this->params];
}

private function checkParameters(string $uri)
Expand Down

0 comments on commit 6a39da0

Please sign in to comment.