|
@@ -108,8 +108,10 @@
|
|
|
}
|
|
|
// Prefixed path routers
|
|
|
foreach($this->routers as $prefix => $router){
|
|
|
- $router->handle($url["path"], $req, $res, null, $onerror);
|
|
|
- $handled = $handled || $router->handled;
|
|
|
+ if(strpos($url["path"], $prefix, 0 ) == 0){
|
|
|
+ $router->handle($url["path"], $req, $res, null, $onerror);
|
|
|
+ $handled = $handled || $router->handled;
|
|
|
+ }
|
|
|
}
|
|
|
// Base router for non-prefixed paths
|
|
|
$this->router->handle($url["path"], $req, $res, function($req, $res) use($handled, $self, $url){
|
|
@@ -125,20 +127,36 @@
|
|
|
$this->_onerror = $fn;
|
|
|
return $this;
|
|
|
}
|
|
|
+ public function base(string $base = null){
|
|
|
+ if(is_null($base)){
|
|
|
+ return $this->router->base;
|
|
|
+ }else{
|
|
|
+ foreach($this->domains as &$router){
|
|
|
+ if($router instanceof Router){
|
|
|
+ $router->base($base);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach($this->routers as $prefix => &$router){
|
|
|
+ $router->base("{$base}/{$prefix}");
|
|
|
+ }
|
|
|
+ $this->router->base($base);
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+ }
|
|
|
public function route(string $path, callable $fn){
|
|
|
$this->router->path($path, $fn);
|
|
|
return $this;
|
|
|
}
|
|
|
public function prefix(string $prefix, callable $fn){
|
|
|
if(!$this->routers[$prefix]){
|
|
|
- $this->routers[$prefix] = new Router($prefix);
|
|
|
+ $this->routers[$prefix] = new Router("{$this->router->base}/{$prefix}");
|
|
|
}
|
|
|
$fn($this->routers[$prefix]);
|
|
|
return $this;
|
|
|
}
|
|
|
public function domain(string $host, callable $fn){
|
|
|
if(!isset($this->domains[$host])){
|
|
|
- $this->domains[$host] = new Router();
|
|
|
+ $this->domains[$host] = new Router($this->router->base);
|
|
|
}
|
|
|
$fn($this->domains[$host]);
|
|
|
return $this;
|
|
@@ -184,4 +202,5 @@
|
|
|
App::shutdown_error(new App\Exception($error->getMessage(), $error->getCode(), $error, $error->getFile(), $error->getLine(), $error->getTrace()));
|
|
|
}
|
|
|
});
|
|
|
+ gc_enable();
|
|
|
?>
|