|
@@ -8,7 +8,7 @@
|
|
|
private $_base = '/';
|
|
|
private $responses = [];
|
|
|
private $_handled = false;
|
|
|
- public function __construct($base = null, $paths = null){
|
|
|
+ public function __construct(string $base = null, array $paths = null){
|
|
|
if($paths != null){
|
|
|
$this->paths($paths);
|
|
|
}
|
|
@@ -35,13 +35,13 @@
|
|
|
public function __toString(){
|
|
|
return "[Router]";
|
|
|
}
|
|
|
- public function base($base){
|
|
|
+ public function base(string $base){
|
|
|
$this->_base = $base;
|
|
|
}
|
|
|
- public function url($url){
|
|
|
+ public function url(string $url){
|
|
|
return preg_replace('/(\/+)/','/',$url);
|
|
|
}
|
|
|
- public function prefix($prefix, Callable $fn){
|
|
|
+ public function prefix(string $prefix, Callable $fn){
|
|
|
$found = false;
|
|
|
foreach($this->_routers as $k => $router){
|
|
|
if($router->base == $prefix){
|
|
@@ -57,7 +57,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function path($path, Callable $fn){
|
|
|
+ public function path(string $path, Callable $fn){
|
|
|
$obj = false;
|
|
|
foreach($this->_paths as $k => $p){
|
|
|
if($p->path == $path){
|
|
@@ -70,7 +70,7 @@
|
|
|
}
|
|
|
return $obj->handle($fn);
|
|
|
}
|
|
|
- public function paths($paths){
|
|
|
+ public function paths(array $paths){
|
|
|
foreach($paths as $path => $fn){
|
|
|
$this->path($path,$fn);
|
|
|
}
|
|
@@ -78,7 +78,7 @@
|
|
|
public function clear(){
|
|
|
$this->_paths = [];
|
|
|
}
|
|
|
- public function handle($path, $req = null,$res = null,Callable $fn = null, Callable $onerror = null){
|
|
|
+ public function handle(string $path, Request $req = null,Response $res = null, Callable $fn = null, Callable $onerror = null){
|
|
|
if(strpos($path, $this->base) !== false){
|
|
|
$path = substr($path,strpos($path,$this->base)+strlen($this->base));
|
|
|
if($path[0] != '/'){
|