Files
kiri-http-server/Handler/OnServer.php
T
2023-04-16 02:41:03 +08:00

97 lines
2.1 KiB
PHP

<?php
namespace Kiri\Server\Handler;
use Kiri\Di\Inject\Container;
use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException;
use Kiri\Server\Events\OnAfterReload;
use Kiri\Server\Events\OnBeforeReload;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Kiri\Server\Abstracts\Server;
use Kiri\Server\Events\OnBeforeShutdown;
use Kiri\Server\Events\OnShutdown;
use Kiri\Server\Events\OnStart;
use Swoole\Server as SServer;
/**
* Class OnServerDefault
* @package Server\Manager
*/
class OnServer extends Server
{
#[Container(EventDispatch::class)]
public EventDispatch $dispatch;
/**
* @param SServer $server
* @throws ConfigException
* @throws ReflectionException
* @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
*/
public function onBeforeShutdown(SServer $server)
{
$this->dispatch->dispatch(new OnBeforeShutdown($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onShutdown(SServer $server)
{
$this->dispatch->dispatch(new OnShutdown($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onBeforeReload(SServer $server)
{
$this->dispatch->dispatch(new OnBeforeReload($server));
}
/**
* @param SServer $server
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function onAfterReload(SServer $server)
{
$this->dispatch->dispatch(new OnAfterReload($server));
}
}