|
@@ -13,7 +13,7 @@
|
|
|
private $routers;
|
|
|
private $router;
|
|
|
public $_onerror;
|
|
|
- public $request;
|
|
|
+ public $request = null;
|
|
|
public $response;
|
|
|
public function __construct(string $name, callable $fn = null, array $events = null){
|
|
|
$this->name = $name;
|
|
@@ -78,7 +78,7 @@
|
|
|
public static function shutdown_error($error){
|
|
|
foreach(static::$apps as $k => $app){
|
|
|
if(is_null($app->request)){
|
|
|
- $app->$request = new Request(static::get_url(), getallheaders(), file_get_contents( 'php://input','r'));
|
|
|
+ $app->request = new Request(static::get_url(), getallheaders(), file_get_contents( 'php://input','r'));
|
|
|
}
|
|
|
$app->onerror($app->request, $app->response, $error);
|
|
|
$app->response->shutdown();
|
|
@@ -128,7 +128,7 @@
|
|
|
// Base router for non-prefixed paths
|
|
|
$this->router->handle($url["path"], $req, $res, function($req, $res) use($handled, $self){
|
|
|
if(!$handled){
|
|
|
- $self->onerror($req, $res,new Error("Not Found", 404));
|
|
|
+ $self->onerror($req, $res,new App\Exception("Not Found", 404));
|
|
|
}
|
|
|
}, $onerror);
|
|
|
$this->fire('afterhandle', $req, $res);
|
|
@@ -166,6 +166,13 @@
|
|
|
}
|
|
|
return $this;
|
|
|
}
|
|
|
+ public function bind(string $hosts, callable $fn){
|
|
|
+ $hosts = array_map(function($item){
|
|
|
+ return trim($item);
|
|
|
+ }, explode(',', $hosts));
|
|
|
+ $host = array_pop($hosts);
|
|
|
+ return $this->map_domain($host, $hosts)->domain($host, $fn);
|
|
|
+ }
|
|
|
public function onerror(Request $req, Response $res, $error){
|
|
|
$this->fire('error', $error);
|
|
|
$fn = $this->_onerror;
|