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\Annotation\Inject;
|
|
|
|
|
use Kiri\Events\EventDispatch;
|
|
|
|
|
use Kiri\Exception\ConfigException;
|
|
|
|
|
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-01-09 03:49:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class OnServerDefault
|
|
|
|
|
* @package Server\Manager
|
|
|
|
|
*/
|
|
|
|
|
class OnServer extends Server
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var EventDispatch
|
|
|
|
|
*/
|
|
|
|
|
#[Inject(EventDispatch::class)]
|
|
|
|
|
public EventDispatch $eventDispatch;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Swoole\Server $server
|
|
|
|
|
* @throws ConfigException
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
*/
|
|
|
|
|
public function onStart(\Swoole\Server $server)
|
|
|
|
|
{
|
|
|
|
|
$this->setProcessName(sprintf('start[%d].server', $server->master_pid));
|
|
|
|
|
|
|
|
|
|
$this->eventDispatch->dispatch(new OnStart($server));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Swoole\Server $server
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
*/
|
|
|
|
|
public function onBeforeShutdown(\Swoole\Server $server)
|
|
|
|
|
{
|
|
|
|
|
$this->eventDispatch->dispatch(new OnBeforeShutdown($server));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Swoole\Server $server
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
*/
|
|
|
|
|
public function onShutdown(\Swoole\Server $server)
|
|
|
|
|
{
|
|
|
|
|
$this->eventDispatch->dispatch(new OnShutdown($server));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|