Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 526256302d | |||
| 95254ac300 | |||
| fdf7757b6a | |||
| 6e4a045c7d | |||
| 03d16d8157 | |||
| c8041cc09e | |||
| 976f67a838 | |||
| c7e0cd4948 | |||
| 3fc1b16f33 | |||
| 103b757a05 |
+1
-1
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user