2023-04-24 10:54:56 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Kiri\Router;
|
|
|
|
|
|
|
|
|
|
use Kiri\Di\Interface\ResponseEmitterInterface;
|
2023-08-16 01:01:47 +08:00
|
|
|
use Kiri\Server\Events\OnAfterRequest;
|
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2023-04-24 10:54:56 +08:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2023-08-16 01:01:47 +08:00
|
|
|
use ReflectionException;
|
2023-04-24 10:54:56 +08:00
|
|
|
|
2023-04-24 14:23:24 +08:00
|
|
|
class SwowHttpResponseEmitter implements ResponseEmitterInterface
|
2023-04-24 10:54:56 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2023-08-16 01:01:47 +08:00
|
|
|
/**
|
|
|
|
|
* @param Response $proxy
|
|
|
|
|
* @param object $response
|
2023-10-17 14:50:46 +08:00
|
|
|
* @param object $request
|
2023-08-16 01:01:47 +08:00
|
|
|
* @return void
|
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
*/
|
2023-10-17 14:50:46 +08:00
|
|
|
public function sender(ResponseInterface $proxy, object $response, object $request): void
|
2023-04-24 10:54:56 +08:00
|
|
|
{
|
|
|
|
|
// TODO: Implement sender() method.
|
|
|
|
|
$proxy->withHeader('Server', 'Swow');
|
2023-10-17 14:50:46 +08:00
|
|
|
$proxy->withHeader('Run-Time', $this->getRunTime($request));
|
|
|
|
|
$response->sendHttpResponse($proxy);
|
2023-08-16 01:01:47 +08:00
|
|
|
|
|
|
|
|
event(new OnAfterRequest());
|
|
|
|
|
}
|
2023-04-24 10:54:56 +08:00
|
|
|
|
2023-10-17 14:50:46 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param object $request
|
|
|
|
|
* @return float
|
|
|
|
|
*/
|
|
|
|
|
protected function getRunTime(object $request): float
|
|
|
|
|
{
|
|
|
|
|
return microtime(true) - +$request->getServerParam('request_time_float');
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 10:54:56 +08:00
|
|
|
}
|