This commit is contained in:
xl
2023-05-25 16:59:17 +08:00
parent 4efac235a0
commit 76cb95a184
6 changed files with 10 additions and 15 deletions
+3 -4
View File
@@ -4,7 +4,6 @@ namespace Kiri\Server\Abstracts;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
@@ -76,7 +75,7 @@ class AsyncServer implements ServerInterface
*/ */
private function initRpcListen(): void private function initRpcListen(): void
{ {
$rpcService = Config::get('rpc', []); $rpcService = \config('rpc', []);
if (!empty($rpcService)) { if (!empty($rpcService)) {
$this->addListener(instance(SConfig::class, [], $rpcService)); $this->addListener(instance(SConfig::class, [], $rpcService));
} }
@@ -123,7 +122,7 @@ class AsyncServer implements ServerInterface
throw new NotFindClassException('Unknown server type ' . $config->type); throw new NotFindClassException('Unknown server type ' . $config->type);
} }
$this->initServer($match, $config, $daemon); $this->initServer($match, $config, $daemon);
$this->onEventListen($this->server, Config::get('server.events', [])); $this->onEventListen($this->server, \config('server.events', []));
$this->onEventListen($this->server, $config->events); $this->onEventListen($this->server, $config->events);
$this->onTaskListen(); $this->onTaskListen();
} }
@@ -175,7 +174,7 @@ class AsyncServer implements ServerInterface
*/ */
protected function systemConfig(SConfig $config, int $daemon): array protected function systemConfig(SConfig $config, int $daemon): array
{ {
$settings = array_merge(Config::get('server.settings', []), $config->settings); $settings = array_merge(\config('server.settings', []), $config->settings);
$settings[Constant::OPTION_DAEMONIZE] = (bool)$daemon; $settings[Constant::OPTION_DAEMONIZE] = (bool)$daemon;
$settings[Constant::OPTION_ENABLE_REUSE_PORT] = true; $settings[Constant::OPTION_ENABLE_REUSE_PORT] = true;
$settings[Constant::OPTION_PID_FILE] = storage('.swoole.pid'); $settings[Constant::OPTION_PID_FILE] = storage('.swoole.pid');
+1 -2
View File
@@ -5,7 +5,6 @@ namespace Kiri\Server\Abstracts;
use Closure; use Closure;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Server\Contract\OnProcessInterface; use Kiri\Server\Contract\OnProcessInterface;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
@@ -186,7 +185,7 @@ class ProcessManager extends Component
public function extracted(mixed $custom, Process $process): void public function extracted(mixed $custom, Process $process): void
{ {
set_env('environmental', Kiri::PROCESS); set_env('environmental', Kiri::PROCESS);
$system = sprintf('[%s].Custom Process', Config::get('id', 'system-service')); $system = sprintf('[%s].Custom Process', \config('id', 'system-service'));
Kiri::getLogger()->alert($system . ' ' . $custom->getName() . ' start.'); Kiri::getLogger()->alert($system . ' ' . $custom->getName() . ' start.');
if (Kiri::getPlatform()->isLinux()) { if (Kiri::getPlatform()->isLinux()) {
$process->name($system . '[' . $process->pid . '].' . $custom->getName()); $process->name($system . '[' . $process->pid . '].' . $custom->getName());
+1 -1
View File
@@ -64,7 +64,7 @@ trait TraitServer
*/ */
public function onSignal(): void public function onSignal(): void
{ {
$signal = \Kiri\Abstracts\Config::get('signal', []); $signal = \Kiri\Abstracts\\config('signal', []);
$this->onPcntlSignal(SIGINT, [$this, 'onSigint']); $this->onPcntlSignal(SIGINT, [$this, 'onSigint']);
foreach ($signal as $sig => $value) { foreach ($signal as $sig => $value) {
if (is_array($value) && is_string($value[0])) { if (is_array($value) && is_string($value[0])) {
+1 -2
View File
@@ -4,7 +4,6 @@ namespace Kiri\Server\Handler;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Config;
use Kiri\Core\Help; use Kiri\Core\Help;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Server\Events\OnAfterWorkerStart; use Kiri\Server\Events\OnAfterWorkerStart;
@@ -108,7 +107,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server
protected function system_mail($messageContent): void protected function system_mail($messageContent): void
{ {
try { try {
$email = Config::get('email', ['enable' => false]); $email = \config('email', ['enable' => false]);
if (!empty($email) && ($email['enable'] ?? false)) { if (!empty($email) && ($email['enable'] ?? false)) {
Help::sendEmail($email, 'Service Error', $messageContent); Help::sendEmail($email, 'Service Error', $messageContent);
} }
+3 -4
View File
@@ -5,7 +5,6 @@ namespace Kiri\Server;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Config;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Router\Router; use Kiri\Router\Router;
@@ -41,7 +40,7 @@ class Server
*/ */
public function __construct() public function __construct()
{ {
$this->class = Config::get('server.type', AsyncServer::class); $this->class = \config('server.type', AsyncServer::class);
} }
@@ -78,7 +77,7 @@ class Server
$manager->scan_build_route(); $manager->scan_build_route();
$manager = $this->manager(); $manager = $this->manager();
$manager->initCoreServers(Config::get('server', [], true), $this->daemon); $manager->initCoreServers(\config('server', [], true), $this->daemon);
$manager->start(); $manager->start();
} }
@@ -121,7 +120,7 @@ class Server
*/ */
public function shutdown(): void public function shutdown(): void
{ {
$configs = Config::get('server', [], true); $configs = \config('server', [], true);
$state = Kiri::getDi()->get(State::class); $state = Kiri::getDi()->get(State::class);
foreach ($this->manager()->sortService($configs['ports'] ?? []) as $config) { foreach ($this->manager()->sortService($configs['ports'] ?? []) as $config) {
+1 -2
View File
@@ -4,7 +4,6 @@ namespace Kiri\Server;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Server\Abstracts\TraitServer; use Kiri\Server\Abstracts\TraitServer;
use Swoole\Process; use Swoole\Process;
@@ -23,7 +22,7 @@ class State extends Component
*/ */
public function init(): void public function init(): void
{ {
$this->servers = Config::get('server.ports'); $this->servers = \config('server.ports');
} }