Compare commits

...

10 Commits

Author SHA1 Message Date
as2252258 526256302d eee 2024-09-04 10:14:31 +08:00
as2252258 95254ac300 eee 2024-09-04 10:07:59 +08:00
as2252258 fdf7757b6a eee 2024-09-03 15:05:19 +08:00
as2252258 6e4a045c7d eee 2024-09-03 14:47:30 +08:00
as2252258 03d16d8157 eee 2024-08-29 18:06:58 +08:00
as2252258 c8041cc09e eee 2024-08-29 17:01:09 +08:00
as2252258 976f67a838 eee 2024-05-01 02:06:14 +08:00
as2252258 c7e0cd4948 eee 2024-05-01 02:02:58 +08:00
as2252258 3fc1b16f33 eee 2024-04-15 15:39:31 +08:00
as2252258 103b757a05 eee 2024-04-15 15:39:03 +08:00
6 changed files with 55 additions and 43 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ if (!function_exists('json_validator')) {
*/
function json_validator(string $data): bool
{
return is_null(json_decode($data));
return is_array(json_decode($data, true));
}
}
+5 -13
View File
@@ -2,11 +2,11 @@
namespace Kiri\Actor;
use Kiri\Server\Abstracts\BaseProcess;
use Kiri\Server\Processes\AbstractProcess;
use Swoole\Coroutine;
use Swoole\Process;
class ActorProcess extends BaseProcess
class ActorProcess extends AbstractProcess
{
/**
@@ -21,7 +21,7 @@ class ActorProcess extends BaseProcess
public function getName(): string
{
// TODO: Change the autogenerated stub
return '[' . \config('id', 'system-service') . '].Actor Manager';
return 'Actor Manager';
}
@@ -39,17 +39,9 @@ class ActorProcess extends BaseProcess
/**
* @return $this
* @return void
*/
public function onSigterm(): static
public function onSigterm(): void
{
// TODO: Implement onSigterm() method.
Coroutine::create(function () {
$sign = Coroutine::waitSignal(SIGINT | SIGTERM);
if ($sign) {
$this->onShutdown(true);
}
});
return $this;
}
}
+31 -1
View File
@@ -14,11 +14,16 @@ use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri;
use Kiri\Error\StdoutLogger;
use ReflectionException;
use Kiri\Events\EventDispatch;
use Kiri\Events\EventProvider;
use Psr\Container\ContainerInterface;
/**
* Class Component
* @package Kiri\Base
* @property ContainerInterface $container
* @property EventDispatch $dispatch
* @property EventProvider $provider
*/
class Component implements Configure
{
@@ -96,4 +101,29 @@ class Component implements Configure
}
/**
* @return EventDispatch
*/
public function getDispatch(): EventDispatch
{
return Kiri::getDi()->get(EventDispatch::class);
}
/**
* @return EventProvider
*/
public function getProvider(): EventProvider
{
return Kiri::getDi()->get(EventProvider::class);
}
/**
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface
{
return Kiri::getDi();
}
}
-13
View File
@@ -4,24 +4,11 @@ declare(strict_types=1);
namespace Kiri\Abstracts;
use Kiri;
use Psr\Container\ContainerInterface;
/**
* Class Providers
* @package Kiri\Abstracts
* @property-read ContainerInterface $container
*/
abstract class Providers extends Component implements Provider
{
/**
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface
{
return Kiri::getDi();
}
}
+3 -10
View File
@@ -34,13 +34,6 @@ class ErrorHandler extends Component implements ErrorInterface
public string $category = 'app';
/**
* @var ContainerInterface
*/
#[Container(ContainerInterface::class)]
public ContainerInterface $container;
/**
* @param array|Closure|null $callback
* @return void
@@ -51,7 +44,7 @@ class ErrorHandler extends Component implements ErrorInterface
if (empty($callback)) {
$callback = [$this, 'exceptionHandler'];
} else if (is_array($callback) && is_string($callback[0])) {
$callback[0] = $this->container->get($callback[0]);
$callback[0] = \Kiri::getDi()->get($callback[0]);
}
set_exception_handler($callback);
}
@@ -67,7 +60,7 @@ class ErrorHandler extends Component implements ErrorInterface
if (empty($callback)) {
$callback = [$this, 'errorHandler'];
} else if (is_array($callback) && is_string($callback[0])) {
$callback[0] = $this->container->get($callback[0]);
$callback[0] = \Kiri::getDi()->get($callback[0]);
}
set_error_handler($callback);
}
@@ -83,7 +76,7 @@ class ErrorHandler extends Component implements ErrorInterface
if (empty($callback)) {
$callback = [$this, 'shutdown'];
} else if (is_array($callback) && is_string($callback[0])) {
$callback[0] = $this->container->get($callback[0]);
$callback[0] = \Kiri::getDi()->get($callback[0]);
}
register_shutdown_function($callback);
}
+15 -5
View File
@@ -14,6 +14,7 @@ use Kiri;
use Kiri\Exception\RedisConnectException;
use Kiri\Pool\Pool;
use RedisException;
use wchat\common\Result;
use function config;
/**
@@ -133,7 +134,7 @@ SCRIPT;
*/
public function destroy(): void
{
$this->pool()->close($this->host);
$this->pool()->close($this->getName());
}
@@ -152,7 +153,7 @@ SCRIPT;
return trigger_print_error(throwable($throwable));
} finally {
if ($client->ping('h') == 'h') {
$this->pool()->push($this->host, $client);
$this->pool()->push($this->getName(), $client);
}
}
}
@@ -164,7 +165,7 @@ SCRIPT;
*/
private function getClient(): \Redis
{
return $this->pool()->get($this->host);
return $this->pool()->get($this->getName());
}
@@ -175,13 +176,22 @@ SCRIPT;
protected function pool(): Pool
{
$pool = Kiri::getPool();
if (!$pool->hasChannel($this->host)) {
$pool->created($this->host, $this->pool['max'], [$this, 'connect']);
if (!$pool->hasChannel($this->getName())) {
$pool->created($this->getName(), $this->pool['max'], [$this, 'connect']);
}
return $pool;
}
/**
* @return string
*/
private function getName(): string
{
return 'redis.' . $this->host;
}
/**
* @return \Redis
* @throws