Typing and 404

This commit is contained in:
sheychen 2017-09-10 20:14:22 +02:00
parent 0ca0c23cee
commit 9b5983a35f
2 changed files with 5 additions and 5 deletions

View File

@ -59,11 +59,11 @@ class App{
$this->router = new Router(isset($data['router']) ? $data['router'] : Path::get('config').'/Routes.php'); $this->router = new Router(isset($data['router']) ? $data['router'] : Path::get('config').'/Routes.php');
} }
public function run($uri = null, array $filters = array()){ public function run(string $uri = null, array $filters = array()){
$route = $this->router->run(($uri ?: $_SERVER['REQUEST_URI']), $filters); $route = $this->router->run(($uri ?: $_SERVER['REQUEST_URI']), $filters);
if(!isset($route)) if(!isset($route))
$this->error(new HttpException(404, 'Not Found')); $this->error(new HttpException(404));
try{ try{
$route->call($this, $this->config['namespace'], $this->config['controller']); $route->call($this, $this->config['namespace'], $this->config['controller']);

View File

@ -31,7 +31,7 @@ class Router{
* @param callable|string $callable Function to run or 'Controller#function' * @param callable|string $callable Function to run or 'Controller#function'
* @return Route * @return Route
*/ */
public function add(string $path, $callable):Route{ public function add(string $path, $callable): Route{
$route = new Route($path, $callable); $route = new Route($path, $callable);
$this->routes[] = $route; $this->routes[] = $route;
return $route; return $route;
@ -44,7 +44,7 @@ class Router{
* @param array $filters * @param array $filters
* @return Route|null * @return Route|null
*/ */
public function run(string $url, array $filters):?Route{ public function run(string $url, array $filters){
foreach($this->routes as $route){ foreach($this->routes as $route){
if($route->match($url, $filters)) if($route->match($url, $filters))
return $route; return $route;
@ -58,7 +58,7 @@ class Router{
* @param string $name * @param string $name
* @return Route|null * @return Route|null
*/ */
public function get(string $name):?Route{ public function get(string $name){
foreach($this->routes as $route){ foreach($this->routes as $route){
if($route->matchName($name)) if($route->matchName($name))
return $route; return $route;