eee
This commit is contained in:
@@ -4,12 +4,16 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Router;
|
namespace Kiri\Router;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Kiri\Di\Inject\Container;
|
||||||
use Kiri\Di\Interface\ResponseEmitterInterface;
|
use Kiri\Di\Interface\ResponseEmitterInterface;
|
||||||
|
use Kiri\Events\EventDispatch;
|
||||||
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Server\Events\OnAfterRequest;
|
use Kiri\Server\Events\OnAfterRequest;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use SplPriorityQueue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +23,42 @@ class SwooleHttpResponseEmitter implements ResponseEmitterInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EventProvider
|
||||||
|
*/
|
||||||
|
#[Container(EventProvider::class)]
|
||||||
|
public EventProvider $provider;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EventDispatch
|
||||||
|
*/
|
||||||
|
#[Container(EventDispatch::class)]
|
||||||
|
public EventDispatch $dispatch;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SplPriorityQueue
|
||||||
|
*/
|
||||||
|
protected SplPriorityQueue $events;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OnAfterRequest
|
||||||
|
*/
|
||||||
|
protected OnAfterRequest $afterRequest;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->afterRequest = new OnAfterRequest();
|
||||||
|
$this->events = $this->provider->getListenersForEvent($this->afterRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $proxy
|
* @param Response $proxy
|
||||||
* @param object $response
|
* @param object $response
|
||||||
@@ -35,7 +75,7 @@ class SwooleHttpResponseEmitter implements ResponseEmitterInterface
|
|||||||
|
|
||||||
$proxy->end($response);
|
$proxy->end($response);
|
||||||
|
|
||||||
// event(new OnAfterRequest());
|
$this->dispatch->execute($this->events, $this->afterRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,55 @@
|
|||||||
|
|
||||||
namespace Kiri\Router;
|
namespace Kiri\Router;
|
||||||
|
|
||||||
|
use Kiri\Di\Inject\Container;
|
||||||
use Kiri\Di\Interface\ResponseEmitterInterface;
|
use Kiri\Di\Interface\ResponseEmitterInterface;
|
||||||
|
use Kiri\Events\EventDispatch;
|
||||||
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Server\Events\OnAfterRequest;
|
use Kiri\Server\Events\OnAfterRequest;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use SplPriorityQueue;
|
||||||
|
|
||||||
class SwowHttpResponseEmitter implements ResponseEmitterInterface
|
class SwowHttpResponseEmitter implements ResponseEmitterInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EventProvider
|
||||||
|
*/
|
||||||
|
#[Container(EventProvider::class)]
|
||||||
|
public EventProvider $provider;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EventDispatch
|
||||||
|
*/
|
||||||
|
#[Container(EventDispatch::class)]
|
||||||
|
public EventDispatch $dispatch;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SplPriorityQueue
|
||||||
|
*/
|
||||||
|
protected SplPriorityQueue $events;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OnAfterRequest
|
||||||
|
*/
|
||||||
|
protected OnAfterRequest $afterRequest;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->afterRequest = new OnAfterRequest();
|
||||||
|
$this->events = $this->provider->getListenersForEvent($this->afterRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $proxy
|
* @param Response $proxy
|
||||||
@@ -29,7 +68,7 @@ class SwowHttpResponseEmitter implements ResponseEmitterInterface
|
|||||||
$proxy->withHeader('Run-Time', $this->getRunTime($request));
|
$proxy->withHeader('Run-Time', $this->getRunTime($request));
|
||||||
$response->sendHttpResponse($proxy);
|
$response->sendHttpResponse($proxy);
|
||||||
|
|
||||||
// event(new OnAfterRequest());
|
$this->dispatch->execute($this->events, $this->afterRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user