diff --git a/src/SwooleHttpResponseEmitter.php b/src/SwooleHttpResponseEmitter.php index 1959cc1..44c8a97 100644 --- a/src/SwooleHttpResponseEmitter.php +++ b/src/SwooleHttpResponseEmitter.php @@ -4,12 +4,16 @@ declare(strict_types=1); namespace Kiri\Router; use Exception; +use Kiri\Di\Inject\Container; use Kiri\Di\Interface\ResponseEmitterInterface; +use Kiri\Events\EventDispatch; +use Kiri\Events\EventProvider; use Kiri\Server\Events\OnAfterRequest; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; 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 object $response @@ -35,7 +75,7 @@ class SwooleHttpResponseEmitter implements ResponseEmitterInterface $proxy->end($response); -// event(new OnAfterRequest()); + $this->dispatch->execute($this->events, $this->afterRequest); } diff --git a/src/SwowHttpResponseEmitter.php b/src/SwowHttpResponseEmitter.php index e267941..e3523c7 100644 --- a/src/SwowHttpResponseEmitter.php +++ b/src/SwowHttpResponseEmitter.php @@ -2,16 +2,55 @@ namespace Kiri\Router; +use Kiri\Di\Inject\Container; use Kiri\Di\Interface\ResponseEmitterInterface; +use Kiri\Events\EventDispatch; +use Kiri\Events\EventProvider; use Kiri\Server\Events\OnAfterRequest; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; use ReflectionException; +use SplPriorityQueue; 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 @@ -29,7 +68,7 @@ class SwowHttpResponseEmitter implements ResponseEmitterInterface $proxy->withHeader('Run-Time', $this->getRunTime($request)); $response->sendHttpResponse($proxy); -// event(new OnAfterRequest()); + $this->dispatch->execute($this->events, $this->afterRequest); }