改名
This commit is contained in:
@@ -39,10 +39,9 @@ class OnRequest extends Callback
|
||||
/** @var HRequest $sRequest */
|
||||
[$sRequest, $sResponse] = static::setContext($request, $response);
|
||||
if ($sRequest->is('favicon.ico')) {
|
||||
$params = $sResponse->send($sRequest->isNotFound(), 200);
|
||||
} else {
|
||||
$params = $sResponse->send(Snowflake::app()->getRouter()->dispatch(), 200);
|
||||
return $params = $sResponse->send($sRequest->isNotFound(), 200);
|
||||
}
|
||||
return $params = Snowflake::app()->getRouter()->dispatch();
|
||||
} catch (Error | \Throwable $exception) {
|
||||
$params = $this->sendErrorMessage($sResponse ?? null, $exception, $response);
|
||||
} finally {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -239,6 +239,21 @@ if (!function_exists('response')) {
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('send')) {
|
||||
|
||||
/**
|
||||
* @param $context
|
||||
* @param $statusCode
|
||||
* @return bool|Response|stdClass|string
|
||||
* @throws Exception
|
||||
*/
|
||||
function send($context, $statusCode = 200)
|
||||
{
|
||||
return \response()->send($context, $statusCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('redirect')) {
|
||||
|
||||
function redirect($url)
|
||||
|
||||
Reference in New Issue
Block a user