改名
This commit is contained in:
@@ -12,6 +12,7 @@ use HttpServer\Route\Annotation\Annotation;
|
||||
use Snowflake\Core\JSON;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
/**
|
||||
* Class Node
|
||||
@@ -86,6 +87,19 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function afterDispatch($response)
|
||||
{
|
||||
return Coroutine::create(function ($response) {
|
||||
$callback = Reduce::after($this->_after);
|
||||
$callback(\request(), $response);
|
||||
}, [$response]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -95,6 +109,24 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAfters()
|
||||
{
|
||||
return $this->_after;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAfter()
|
||||
{
|
||||
return count($this->_after) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -417,11 +417,16 @@ class Router extends Application implements RouterInterface
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
/** @var Node $node */
|
||||
$request = Context::getContext('request');
|
||||
if (!($node = $this->find_path($request))) {
|
||||
return JSON::to(404, self::NOT_FOUND);
|
||||
return send(JSON::to(404, self::NOT_FOUND));
|
||||
}
|
||||
return $node->dispatch();
|
||||
$response = send($node->dispatch(), 200);
|
||||
if ($node->hasAfter()) {
|
||||
$node->afterDispatch($response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user