Files
kiri-http-server/Handler/OnServer.php
T

102 lines
2.2 KiB
PHP
Raw Normal View History

2022-01-09 03:49:02 +08:00
<?php
2022-01-10 11:39:55 +08:00
namespace Kiri\Server\Handler;
2022-01-09 03:49:02 +08:00
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
2022-06-16 17:38:22 +08:00
use Kiri\Server\Events\OnAfterReload;
use Kiri\Server\Events\OnBeforeReload;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
2022-01-09 03:49:02 +08:00
use ReflectionException;
2022-01-10 11:39:55 +08:00
use Kiri\Server\Abstracts\Server;
use Kiri\Server\Events\OnBeforeShutdown;
use Kiri\Server\Events\OnShutdown;
use Kiri\Server\Events\OnStart;
2022-06-16 17:38:22 +08:00
use Swoole\Server as SServer;
2022-01-09 03:49:02 +08:00
/**
* Class OnServerDefault
* @package Server\Manager
*/
class OnServer extends Server
{
2022-06-16 17:38:22 +08:00
2022-01-09 03:49:02 +08:00
/**
2022-06-16 17:38:22 +08:00
* @param EventDispatch $dispatch
* @throws \Exception
*/
public function __construct(public EventDispatch $dispatch)
{
parent::__construct();
}
/**
* @param SServer $server
2022-01-09 03:49:02 +08:00
* @throws ConfigException
* @throws ReflectionException
2022-06-16 17:38:22 +08:00
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function onStart(SServer $server)
{
\Kiri::setProcessName(sprintf('start[%d].server', $server->master_pid));
$this->dispatch->dispatch(new OnStart($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
2022-01-09 03:49:02 +08:00
*/
2022-06-16 17:38:22 +08:00
public function onBeforeShutdown(SServer $server)
2022-01-09 03:49:02 +08:00
{
2022-06-16 17:38:22 +08:00
$this->dispatch->dispatch(new OnBeforeShutdown($server));
}
2022-01-09 03:49:02 +08:00
2022-06-16 17:38:22 +08:00
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onShutdown(SServer $server)
{
$this->dispatch->dispatch(new OnShutdown($server));
2022-01-09 03:49:02 +08:00
}
/**
2022-06-16 17:38:22 +08:00
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
2022-01-09 03:49:02 +08:00
* @throws ReflectionException
*/
2022-06-16 17:38:22 +08:00
public function onBeforeReload(SServer $server)
2022-01-09 03:49:02 +08:00
{
2022-06-16 17:38:22 +08:00
$this->dispatch->dispatch(new OnBeforeReload($server));
2022-01-09 03:49:02 +08:00
}
/**
2022-06-16 17:38:22 +08:00
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
2022-01-09 03:49:02 +08:00
* @throws ReflectionException
*/
2022-06-16 17:38:22 +08:00
public function onAfterReload(SServer $server)
2022-01-09 03:49:02 +08:00
{
2022-06-16 17:38:22 +08:00
$this->dispatch->dispatch(new OnAfterReload($server));
2022-01-09 03:49:02 +08:00
}
2022-06-16 17:38:22 +08:00
2022-01-09 03:49:02 +08:00
}