改名
This commit is contained in:
@@ -10,6 +10,7 @@ use Exception;
|
||||
use HttpServer\Application;
|
||||
use HttpServer\Route\Annotation\Annotation;
|
||||
use Snowflake\Core\JSON;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -85,26 +86,6 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAfter()
|
||||
{
|
||||
return count($this->_after) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function afterDispatch($response)
|
||||
{
|
||||
$callback = Reduce::after($this->_after);
|
||||
return $callback(\request(), $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -114,15 +95,6 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAfters()
|
||||
{
|
||||
return $this->_after;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -230,7 +202,11 @@ class Node extends Application
|
||||
*/
|
||||
public function addAfter($handler)
|
||||
{
|
||||
$this->_after[] = $handler;
|
||||
$event = Snowflake::app()->getEvent();
|
||||
if ($event->exists(Event::EVENT_AFTER_REQUEST, $handler)) {
|
||||
return;
|
||||
}
|
||||
$event->on(Event::EVENT_AFTER_REQUEST, $handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -419,27 +419,9 @@ class Router extends Application implements RouterInterface
|
||||
{
|
||||
$request = Context::getContext('request');
|
||||
if (!($node = $this->find_path($request))) {
|
||||
$response = JSON::to(404, self::NOT_FOUND);
|
||||
response()->send($response, 200);
|
||||
} else {
|
||||
response()->send($response = $node->dispatch(), 200);
|
||||
return JSON::to(404, self::NOT_FOUND);
|
||||
}
|
||||
$this->onAfter($response, $node);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param null|Node $node
|
||||
*/
|
||||
private function onAfter($data, $node = null)
|
||||
{
|
||||
Coroutine::defer(function () use ($node, $data) {
|
||||
if (!$node->hasAfter()) {
|
||||
return;
|
||||
}
|
||||
$node->afterDispatch($data);
|
||||
});
|
||||
return $node->dispatch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user