Compare commits
242 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7db58d7e4 | |||
| 87e4bfdbec | |||
| ee761817bf | |||
| 4a4b7db651 | |||
| 905427bccc | |||
| 68ee0244a2 | |||
| 7e43775b04 | |||
| dd4e9be06a | |||
| 73b01c288b | |||
| f4f48ebad7 | |||
| ef95f912cb | |||
| 8bbb6adcc7 | |||
| a855765365 | |||
| 3110e69350 | |||
| 4862e7e913 | |||
| 0a52bd502b | |||
| 95492e2863 | |||
| 3cc0a9bef2 | |||
| d743382868 | |||
| 47f1407118 | |||
| 04395f293d | |||
| a44b7a31ef | |||
| 493ef65ce8 | |||
| 3943142b86 | |||
| 786f96363b | |||
| bcf73a8cad | |||
| 2b152504ec | |||
| e554ad3642 | |||
| c801aec334 | |||
| 2c2c16819a | |||
| a48aa9a20f | |||
| 8dadcbed16 | |||
| 86dd776388 | |||
| d83d0871f5 | |||
| fc6baa83a7 | |||
| 35dd2803fc | |||
| e3527752a7 | |||
| 340e0f1686 | |||
| 2ad6153405 | |||
| 0f172ae62d | |||
| f4596bf02c | |||
| ef4f84f696 | |||
| 08d19c9c05 | |||
| e0537f2ee4 | |||
| 0edcf8c83f | |||
| 6ac2c73a8c | |||
| b1a5db0a6b | |||
| 8ec1a81ecd | |||
| b98de03317 | |||
| 251bca3d64 | |||
| b2a79ef0ed | |||
| d9451f5087 | |||
| 84d8dda8eb | |||
| 1d846a4903 | |||
| fe4f985315 | |||
| c5c1d991f2 | |||
| 9ec6573ca4 | |||
| 9800024d59 | |||
| 57b2214433 | |||
| 2f038e5637 | |||
| 0f238f488d | |||
| 59243a6fed | |||
| fbd7f874ac | |||
| 7aee3c8458 | |||
| f3446da34e | |||
| 755594b4bb | |||
| abcf5e9feb | |||
| f243e19b24 | |||
| 5d91b61f83 | |||
| d3ed35e948 | |||
| c5bfe8110a | |||
| 1c18ee94ee | |||
| f72c73766d | |||
| 092139c0b9 | |||
| 43a1fad278 | |||
| dbc4cb15dd | |||
| 758bd650b5 | |||
| ba804c4d9c | |||
| cac794ca20 | |||
| ea09d3e3ba | |||
| f6552c45ae | |||
| 114f5d0279 | |||
| 5638d171d0 | |||
| fa78d360b0 | |||
| ffc35090b9 | |||
| 5156a606e0 | |||
| 2393ef820f | |||
| 9986900b58 | |||
| 07c52ef08f | |||
| 0a6fdda720 | |||
| 841a6b4a19 | |||
| 873da66a90 | |||
| be9f4281e6 | |||
| 57be085166 | |||
| 454c77f37a | |||
| 323a4b8ff0 | |||
| c66e5120e1 | |||
| 1fa7d3a3ba | |||
| a290108ddd | |||
| 446fd740f2 | |||
| a040099b99 | |||
| 78fdc7c1ca | |||
| dfc249b56c | |||
| 577be309cc | |||
| 9798be99e6 | |||
| e3348a11c8 | |||
| 1643a839b3 | |||
| d4a15d26ed | |||
| 485d926dc0 | |||
| 6a5205e9a1 | |||
| 471f7a92bb | |||
| 429ffe561c | |||
| 27cdf5082f | |||
| 4c3751ca4d | |||
| 5f1eaf8239 | |||
| 8b76ef8e41 | |||
| 981a800053 | |||
| 79544f1ad1 | |||
| 93bd3d3f69 | |||
| 975f6f85a2 | |||
| 5a99181eaf | |||
| da5d74f519 | |||
| c878ed0ba4 | |||
| e7e24a1488 | |||
| 3dba884f64 | |||
| 4b30a59f6a | |||
| 704c0808ea | |||
| e738b084b4 | |||
| 77aa761e82 | |||
| 49ac53e751 | |||
| 2c0a431069 | |||
| 61893335ae | |||
| f87ddff585 | |||
| edcd873ff3 | |||
| 3ac7720f5b | |||
| a1fc45c3d7 | |||
| ac01000524 | |||
| 0a313e2b99 | |||
| 18b77760cd | |||
| 65a874c155 | |||
| 1bf851ff6b | |||
| 3309b101b6 | |||
| 27d8caec00 | |||
| 0cb14bd24b | |||
| 133455a041 | |||
| 9c5ba4b3e9 | |||
| 6db849de8d | |||
| 5506b3e725 | |||
| d1ccbbb5e0 | |||
| c8c95d9dc9 | |||
| 7d0ce48cd0 | |||
| c66b76d0be | |||
| febc53147e | |||
| c6279d6214 | |||
| 8deea95fb8 | |||
| 2512044bc5 | |||
| 3a1a124db3 | |||
| d2df0cbc1a | |||
| 15b6ac1b79 | |||
| 8fb60fcd76 | |||
| c8149e3754 | |||
| f49af928b6 | |||
| 63aadcb31f | |||
| 5f1fd4d93c | |||
| 84e8d26371 | |||
| 85fc29e76c | |||
| ad568fa3a7 | |||
| ea8d4d9611 | |||
| d3e74965f9 | |||
| 389c376c43 | |||
| 81eeaa64e4 | |||
| fbad6d9938 | |||
| 825539c792 | |||
| c73fe2d609 | |||
| ac66f768c3 | |||
| 84e2998139 | |||
| 19cab4f333 | |||
| 7d8c50aed8 | |||
| 8d98dc83be | |||
| 3adea33afe | |||
| 55250de396 | |||
| 5fffe53022 | |||
| 7a0ff2fbc5 | |||
| 4f539f4e78 | |||
| 9af827a11e | |||
| 3ddec68d7f | |||
| a5519b927b | |||
| 8add22f589 | |||
| 54f60e8765 | |||
| 6a60b03678 | |||
| 878e3b262b | |||
| a3ad2a6f17 | |||
| 79b32df2d5 | |||
| f40b79bb08 | |||
| ee380aa520 | |||
| dbf91656cb | |||
| 52845dfdb8 | |||
| 78c187e49f | |||
| fe105bd7d2 | |||
| 021e9ea23a | |||
| 794165fa67 | |||
| 6ef0f8b412 | |||
| fcb8630095 | |||
| ceafc139db | |||
| 283c7c2371 | |||
| 0b170cafb2 | |||
| d036f730ca | |||
| 55727bb219 | |||
| dc477978d3 | |||
| 7dda29a892 | |||
| 567cac606a | |||
| 49d435e4a5 | |||
| 5303c05274 | |||
| f6cb258259 | |||
| affb161ddf | |||
| a80f671a22 | |||
| 497cd95731 | |||
| 3ae85beb16 | |||
| 0a76e991b9 | |||
| bfc591b10a | |||
| b274140708 | |||
| a4a9a5618d | |||
| 0cf17a547e | |||
| 35ea526420 | |||
| 8ba04b4ccc | |||
| b83a0c4c96 | |||
| 21d3738125 | |||
| 2bd18b014d | |||
| 39be8f4b3b | |||
| 043b62688b | |||
| 38f5f57c4d | |||
| 2c7a755663 | |||
| 187b4311eb | |||
| 7d2c2cf7ff | |||
| 3771a8fb22 | |||
| 7561bacda5 | |||
| c7d6032010 | |||
| 48d9c5ce79 | |||
| b9d2288ac7 | |||
| 13877c6d58 | |||
| 320a01d822 | |||
| a435df8453 |
+5
-4
@@ -21,16 +21,17 @@
|
||||
"ext-xml": "*",
|
||||
"ext-curl": "*",
|
||||
"ext-openssl": "*",
|
||||
"symfony/console": "^v5.3",
|
||||
"symfony/console": "v5.3.10",
|
||||
"psr/log": "1.*",
|
||||
"ext-sockets": "*",
|
||||
"ext-pcntl": "*",
|
||||
"ext-posix": "*",
|
||||
"composer-runtime-api": "^2.0",
|
||||
"swiftmailer/swiftmailer": "^6.0",
|
||||
"swiftmailer/swiftmailer": "v6.3.*",
|
||||
"psr/container": "^2.0",
|
||||
"psr/http-server-middleware": "^1.0",
|
||||
"game-worker/kiri-event": "v1.0"
|
||||
"psr/http-server-middleware": "1.0.1",
|
||||
"game-worker/kiri-event": "v1.0",
|
||||
"ext-inotify": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
+48
-1
@@ -18,6 +18,7 @@ use Kiri\Exception\NotFindClassException;
|
||||
use Kiri\Kiri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Server\ServerManager;
|
||||
use Swoole\Process;
|
||||
use Swoole\WebSocket\Server;
|
||||
|
||||
if (!function_exists('make')) {
|
||||
@@ -52,6 +53,38 @@ if (!function_exists('make')) {
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('checkPortIsAlready')) {
|
||||
|
||||
|
||||
/**
|
||||
* @param $port
|
||||
* @return bool|string
|
||||
* @throws Exception
|
||||
*/
|
||||
function checkPortIsAlready($port): bool|string
|
||||
{
|
||||
if (!Kiri::getPlatform()->isLinux()) {
|
||||
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
||||
if (empty($output)) return false;
|
||||
$output = explode(PHP_EOL, $output[0]);
|
||||
return $output[0];
|
||||
}
|
||||
|
||||
$serverPid = file_get_contents(storage('.swoole.pid'));
|
||||
if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) {
|
||||
Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM);
|
||||
}
|
||||
|
||||
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||
if (empty($output)) {
|
||||
return false;
|
||||
}
|
||||
return explode('/', $output[0])[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('done')) {
|
||||
|
||||
/**
|
||||
@@ -59,12 +92,26 @@ if (!function_exists('done')) {
|
||||
*/
|
||||
function done()
|
||||
{
|
||||
ServerManager::setEnv('state', 'exit');
|
||||
set_env('state', 'exit');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('set_env')) {
|
||||
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
function set_env($key, $value)
|
||||
{
|
||||
putenv(sprintf('%s=%s', $key, $value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('enable_file_modification_listening')) {
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Annotation\Annotation as SAnnotation;
|
||||
use Database\Connection;
|
||||
use Exception;
|
||||
use Http\Handler\Router;
|
||||
use Kiri\Events\OnBeforeCommandExecute;
|
||||
use Server\Server;
|
||||
use Kafka\KafkaProvider;
|
||||
use Kiri\Async;
|
||||
@@ -28,7 +29,7 @@ use Kiri\Jwt\Jwt;
|
||||
use Kiri\Kiri;
|
||||
use ReflectionException;
|
||||
use Server\ServerManager;
|
||||
use Server\SInterface\OnTaskInterface;
|
||||
use Server\Contract\OnTaskInterface;
|
||||
use Swoole\Table;
|
||||
|
||||
/**
|
||||
@@ -227,6 +228,8 @@ abstract class BaseApplication extends Component
|
||||
$eventProvider->on($key, $value, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (is_array($value)) {
|
||||
if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
|
||||
$eventProvider->on($key, $value, 0);
|
||||
@@ -239,6 +242,7 @@ abstract class BaseApplication extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach ($value as $item) {
|
||||
if (!is_callable($item, true)) {
|
||||
throw new InitException("Class does not hav callback.");
|
||||
|
||||
@@ -21,203 +21,223 @@ use Swoole\Coroutine;
|
||||
class BaseObject implements Configure
|
||||
{
|
||||
|
||||
/**
|
||||
* BaseAbstract constructor.
|
||||
*
|
||||
* @param array $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
if (!empty($config) && is_array($config)) {
|
||||
Kiri::configure($this, $config);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* BaseAbstract constructor.
|
||||
*
|
||||
* @param array $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
if (!empty($config) && is_array($config)) {
|
||||
Kiri::configure($this, $config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array|callable $callback
|
||||
* @param object $scope
|
||||
*/
|
||||
public function async_create(array|callable $callback, object $scope)
|
||||
{
|
||||
Coroutine::create($callback, $scope);
|
||||
}
|
||||
/**
|
||||
* @param array|callable $callback
|
||||
* @param object $scope
|
||||
*/
|
||||
public function async_create(array|callable $callback, object $scope)
|
||||
{
|
||||
Coroutine::create($callback, $scope);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] public static function className(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] public static function className(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$method = 'set' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}($value);
|
||||
} else {
|
||||
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$method = 'set' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}($value);
|
||||
} else {
|
||||
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($name): mixed
|
||||
{
|
||||
$method = 'get' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
} else {
|
||||
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($name): mixed
|
||||
{
|
||||
$method = 'get' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
} else {
|
||||
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param string $model
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addError($message, string $model = 'app'): bool
|
||||
{
|
||||
if ($message instanceof \Throwable) {
|
||||
$this->error(jTraceEx($message));
|
||||
} else {
|
||||
if (!is_string($message)) {
|
||||
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$this->error($message);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
/**
|
||||
* @param $message
|
||||
* @param string $model
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addError($message, string $model = 'app'): bool
|
||||
{
|
||||
if ($message instanceof \Throwable) {
|
||||
$this->error(jTraceEx($message));
|
||||
} else {
|
||||
if (!is_string($message)) {
|
||||
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$this->error($message);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Logger
|
||||
* @throws Exception
|
||||
*/
|
||||
private function logger(): Logger
|
||||
{
|
||||
return Kiri::getDi()->get(Logger::class);
|
||||
}
|
||||
/**
|
||||
* @return Logger
|
||||
* @throws Exception
|
||||
*/
|
||||
private function logger(): Logger
|
||||
{
|
||||
return Kiri::getDi()->get(Logger::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function debug(mixed $message, string $method = __METHOD__, string $file = __FILE__)
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
$message = "\033[35m[" . date('Y-m-d H:i:s') . '][DEBUG]: ' . $message . "\033[0m";
|
||||
$message .= PHP_EOL;
|
||||
|
||||
$this->logger()->debug(Logger::DEBUG, [$message, $method, $file]);
|
||||
}
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function debug(mixed $message, string $method = '', string $file = '')
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
$message = "\033[35m" . $message . "\033[0m";
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function info(mixed $message, string $method = __METHOD__, string $file = __FILE__)
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
$message = "\033[34m[" . date('Y-m-d H:i:s') . '][INFO]: ' . $message . "\033[0m";
|
||||
$message .= PHP_EOL;
|
||||
$context = [];
|
||||
if (!empty($method)) $context['method'] = $method;
|
||||
if (!empty($file)) $context['file'] = $file;
|
||||
|
||||
$this->logger()->info(Logger::NOTICE, [$message, $method, $file]);
|
||||
}
|
||||
$this->logger()->debug($message, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function success(mixed $message, string $method = __METHOD__, string $file = __FILE__)
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
|
||||
$message = "\033[36m[" . date('Y-m-d H:i:s') . '][SUCCESS]: ' . $message . "\033[0m";
|
||||
$message .= PHP_EOL;
|
||||
|
||||
$this->logger()->notice(Logger::NOTICE, [$message, $method, $file]);
|
||||
}
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function info(mixed $message, string $method = '', string $file = '')
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
$message = "\033[34m" . $message . "\033[0m";
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function warning(mixed $message, string $method = __METHOD__, string $file = __FILE__)
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
$context = [];
|
||||
if (!empty($method)) $context['method'] = $method;
|
||||
if (!empty($file)) $context['file'] = $file;
|
||||
|
||||
$message = "\033[33m[" . date('Y-m-d H:i:s') . '][WARNING]: ' . $message . "\033[0m";
|
||||
$message .= PHP_EOL;
|
||||
|
||||
$this->logger()->critical(Logger::NOTICE, [$message, $method, $file]);
|
||||
}
|
||||
$this->logger()->info($message, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param null $method
|
||||
* @param null $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function error(mixed $message, $method = null, $file = null)
|
||||
{
|
||||
if ($message instanceof \Throwable) {
|
||||
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
|
||||
}
|
||||
$content = (empty($method) ? '' : $method . ': ') . $message;
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function success(mixed $message, string $method = '', string $file = '')
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
|
||||
$message = "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $content . "\033[0m";
|
||||
$message = "\033[36m" . $message . "\033[0m";
|
||||
|
||||
if (!empty($file)) {
|
||||
$message .= PHP_EOL . "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $file . "\033[0m";
|
||||
}
|
||||
|
||||
$this->logger()->error(Logger::ERROR, [$message, $method, $file]);
|
||||
}
|
||||
$context = [];
|
||||
if (!empty($method)) $context['method'] = $method;
|
||||
if (!empty($file)) $context['file'] = $file;
|
||||
|
||||
$this->logger()->notice($message, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param string $method
|
||||
* @param string $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function warning(mixed $message, string $method = '', string $file = '')
|
||||
{
|
||||
if (!is_string($message)) {
|
||||
$message = print_r($message, true);
|
||||
}
|
||||
|
||||
$message = "\033[33m" . $message . "\033[0m";
|
||||
|
||||
|
||||
$context = [];
|
||||
if (!empty($method)) $context['method'] = $method;
|
||||
if (!empty($file)) $context['file'] = $file;
|
||||
|
||||
$this->logger()->critical($message, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param null $method
|
||||
* @param null $file
|
||||
* @throws Exception
|
||||
*/
|
||||
public function error(mixed $message, $method = null, $file = null)
|
||||
{
|
||||
if ($message instanceof \Throwable) {
|
||||
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
|
||||
}
|
||||
$content = (empty($method) ? '' : $method . ': ') . $message;
|
||||
|
||||
$message = "\033[41;37m" . $content . "\033[0m";
|
||||
|
||||
if (!empty($file)) {
|
||||
$message .= PHP_EOL . "\03341;37m[" . $file . "\033[0m";
|
||||
}
|
||||
|
||||
$context = [];
|
||||
if (!empty($method)) $context['method'] = $method;
|
||||
if (!empty($file)) $context['file'] = $file;
|
||||
|
||||
$this->logger()->error($message, $context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ use Kiri\Crontab\CrontabProviders;
|
||||
use Kiri\Events\OnAfterCommandExecute;
|
||||
use Kiri\Events\OnBeforeCommandExecute;
|
||||
use Kiri\Exception\NotFindClassException;
|
||||
use Kiri\FileListen\FileChangeCustomProcess;
|
||||
use Kiri\FileListen\HotReload;
|
||||
use ReflectionException;
|
||||
use Server\ServerCommand;
|
||||
use Server\ServerProviders;
|
||||
use stdClass;
|
||||
use Swoole\Process;
|
||||
@@ -30,6 +29,7 @@ use Swoole\Timer;
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ class Application extends BaseApplication
|
||||
$container = Kiri::getDi();
|
||||
|
||||
$console = $container->get(ConsoleApplication::class);
|
||||
$console->add($container->get(FileChangeCustomProcess::class));
|
||||
$console->add($container->get(HotReload::class));
|
||||
}
|
||||
|
||||
|
||||
@@ -192,12 +192,13 @@ class Application extends BaseApplication
|
||||
*/
|
||||
public function execute(array $argv): void
|
||||
{
|
||||
/** @var InputInterface $input */
|
||||
[$input, $output] = $this->argument($argv);
|
||||
try {
|
||||
$console = di(ConsoleApplication::class);
|
||||
$command = $input->getFirstArgument();
|
||||
if (empty($command)) {
|
||||
$command = 'list';
|
||||
$command = 'sw:server';
|
||||
}
|
||||
$command = $console->find($command);
|
||||
if ($command instanceof Command) {
|
||||
@@ -211,6 +212,7 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $argv
|
||||
* @return array
|
||||
@@ -221,6 +223,7 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws NotFindClassException
|
||||
* @throws ReflectionException
|
||||
@@ -229,7 +232,7 @@ class Application extends BaseApplication
|
||||
private function enableFileChange(Command $class, $input, $output): void
|
||||
{
|
||||
fire(new OnBeforeCommandExecute());
|
||||
if (!($class instanceof FileChangeCustomProcess)) {
|
||||
if (!($class instanceof HotReload)) {
|
||||
scan_directory(directory('app'), 'App');
|
||||
}
|
||||
$class->run($input, $output);
|
||||
@@ -238,6 +241,8 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
* @param null $abstracts
|
||||
|
||||
@@ -13,73 +13,76 @@ class LocalService extends Component
|
||||
{
|
||||
|
||||
|
||||
private array $_components = [];
|
||||
private array $_components = [];
|
||||
|
||||
|
||||
private array $_definition = [];
|
||||
private array $_definition = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $define
|
||||
*/
|
||||
public function set($name, $define)
|
||||
{
|
||||
unset($this->_components[$name]);
|
||||
/**
|
||||
* @param $name
|
||||
* @param $define
|
||||
*/
|
||||
public function set($name, $define)
|
||||
{
|
||||
unset($this->_components[$name]);
|
||||
|
||||
$this->_definition[$name] = $define;
|
||||
}
|
||||
$this->_definition[$name] = $define;
|
||||
if (is_object($define) || $define instanceof \Closure) {
|
||||
$this->_components[$name] = $define;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(string $name, $throwException = true)
|
||||
{
|
||||
if (isset($this->_components[$name])) {
|
||||
return $this->_components[$name];
|
||||
}
|
||||
if (isset($this->_definition[$name])) {
|
||||
$definition = $this->_definition[$name];
|
||||
if (is_object($definition) && !$definition instanceof \Closure) {
|
||||
return $this->_components[$name] = $definition;
|
||||
}
|
||||
return $this->_components[$name] = Kiri::createObject($definition);
|
||||
} else if ($throwException) {
|
||||
throw new \Exception("Unknown component ID: $name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(string $name, $throwException = true)
|
||||
{
|
||||
if (isset($this->_components[$name])) {
|
||||
return $this->_components[$name];
|
||||
}
|
||||
if (isset($this->_definition[$name])) {
|
||||
$definition = $this->_definition[$name];
|
||||
if (is_object($definition) && !$definition instanceof \Closure) {
|
||||
return $this->_components[$name] = $definition;
|
||||
}
|
||||
return $this->_components[$name] = Kiri::createObject($definition);
|
||||
} else if ($throwException) {
|
||||
throw new \Exception("Unknown component ID: $name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $components
|
||||
*/
|
||||
public function setComponents(array $components)
|
||||
{
|
||||
foreach ($components as $name => $component) {
|
||||
$this->set($name, $component);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param array $components
|
||||
*/
|
||||
public function setComponents(array $components)
|
||||
{
|
||||
foreach ($components as $name => $component) {
|
||||
$this->set($name, $component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function has($id): bool
|
||||
{
|
||||
return isset($this->_components[$id]) || isset($this->_definition[$id]);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function has($id): bool
|
||||
{
|
||||
return isset($this->_components[$id]) || isset($this->_definition[$id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function remove($id): void
|
||||
{
|
||||
unset($this->_components[$id], $this->_definition[$id]);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function remove($id): void
|
||||
{
|
||||
unset($this->_components[$id], $this->_definition[$id]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
{
|
||||
$path = ['file' => $file, 'line' => $line];
|
||||
|
||||
var_dump(func_get_args());
|
||||
|
||||
$data = Json::to($code, $this->category . ': ' . $message, $path);
|
||||
|
||||
write($data, $this->category);
|
||||
|
||||
@@ -5,8 +5,9 @@ namespace Kiri\Error;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Http\Aspect\OnAspectInterface;
|
||||
use Http\Aspect\OnJoinPointInterface;
|
||||
use Http\Constrict\RequestInterface;
|
||||
use Kiri\IAspect;
|
||||
use Kiri\Kiri;
|
||||
|
||||
|
||||
@@ -14,20 +15,24 @@ use Kiri\Kiri;
|
||||
* Class LoggerAspect
|
||||
* @package Kiri\Error
|
||||
*/
|
||||
class LoggerAspect implements IAspect
|
||||
class LoggerAspect implements OnAspectInterface
|
||||
{
|
||||
|
||||
private float $time;
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $handler
|
||||
* @param array $params
|
||||
* @param OnJoinPointInterface $joinPoint
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invoke(mixed $handler, array $params = []): mixed
|
||||
public function process(OnJoinPointInterface $joinPoint): mixed
|
||||
{
|
||||
return call_user_func($handler, ...$params);
|
||||
$time = microtime(true);
|
||||
|
||||
$response = $joinPoint->process();
|
||||
|
||||
$this->print_runtime($time);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,20 +49,4 @@ class LoggerAspect implements IAspect
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
public function before(): void
|
||||
{
|
||||
// TODO: Implement before() method.
|
||||
$this->time = microtime(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function after(mixed $response): void
|
||||
{
|
||||
// TODO: Implement after() method.
|
||||
$this->print_runtime($this->time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,22 +20,16 @@ use Server\Abstracts\BaseProcess;
|
||||
class LoggerProcess extends BaseProcess
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] public function getProcessName(Process $process): string
|
||||
{
|
||||
// TODO: Implement getProcessName() method.
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
public string $name = 'logger process';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function onHandler(Process $process): void
|
||||
public function process(Process $process): void
|
||||
{
|
||||
// TODO: Implement onHandler() method.
|
||||
$this->message($process);
|
||||
@@ -49,10 +43,6 @@ class LoggerProcess extends BaseProcess
|
||||
*/
|
||||
public function message(Process $process)
|
||||
{
|
||||
if ($this->checkProcessIsStop()) {
|
||||
$this->exit();
|
||||
return;
|
||||
}
|
||||
$message = Json::decode($process->read());
|
||||
if (!empty($message)) {
|
||||
Kiri::writeFile($this->getDirName($message), $message[0], FILE_APPEND);
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\FileListen;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine\Barrier;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FileChangeCustomProcess extends Command
|
||||
{
|
||||
|
||||
|
||||
public bool $isReloading = false;
|
||||
public bool $isReloadingOut = false;
|
||||
public ?array $dirs = [];
|
||||
public int $events;
|
||||
|
||||
public int $int = -1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sw:wather')
|
||||
->setDescription('server start')
|
||||
->addArgument('action', InputArgument::REQUIRED);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
* @throws ConfigException
|
||||
* @throws \Swoole\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// TODO: Implement onHandler() method.
|
||||
set_error_handler([$this, 'onErrorHandler']);
|
||||
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
|
||||
if (!extension_loaded('inotify')) {
|
||||
$driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
|
||||
} else {
|
||||
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
|
||||
}
|
||||
$make = Barrier::make();
|
||||
go(function () {
|
||||
$this->trigger_reload();
|
||||
});
|
||||
go(function () {
|
||||
$sign = Coroutine::waitSignal(SIGTERM, -1);
|
||||
if ($sign) {
|
||||
proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes);
|
||||
}
|
||||
});
|
||||
go(function () use ($driver) {
|
||||
$driver->start();
|
||||
});
|
||||
Barrier::wait($make);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $message
|
||||
* @param $file
|
||||
* @param $line
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onErrorHandler($code, $message, $file, $line)
|
||||
{
|
||||
if (str_contains($message, 'The file descriptor is not an inotify instance')) {
|
||||
return;
|
||||
}
|
||||
debug('Error:' . $message . ' at ' . $file . ':' . $line);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重启
|
||||
* @throws Exception
|
||||
*/
|
||||
public function trigger_reload()
|
||||
{
|
||||
Kiri::getDi()->get(Logger::class)->warning('change reload');
|
||||
|
||||
proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\FileListen;
|
||||
|
||||
use Annotation\Inject;
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Error\Logger;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class HotReload extends Command
|
||||
{
|
||||
|
||||
|
||||
public bool $isReloading = false;
|
||||
public bool $isReloadingOut = false;
|
||||
public ?array $dirs = [];
|
||||
|
||||
public int $events;
|
||||
|
||||
public int $int = -1;
|
||||
|
||||
|
||||
private ?Process $process = null;
|
||||
|
||||
|
||||
public Inotify|Scaner $driver;
|
||||
|
||||
|
||||
#[Inject(Logger::class)]
|
||||
public Logger $logger;
|
||||
|
||||
|
||||
protected mixed $source = null;
|
||||
|
||||
protected mixed $pipes = [];
|
||||
|
||||
protected ?Coroutine\Channel $channel = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sw:wather')
|
||||
->setDescription('server start');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// TODO: Implement onHandler() method.
|
||||
set_error_handler([$this, 'onErrorHandler']);
|
||||
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
|
||||
swoole_async_set(['enable_coroutine' => false]);
|
||||
if (!extension_loaded('inotify')) {
|
||||
$this->driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
|
||||
} else {
|
||||
$this->driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
|
||||
}
|
||||
if (Kiri::getPlatform()->isLinux()) {
|
||||
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
|
||||
}
|
||||
$this->trigger_reload();
|
||||
|
||||
var_dump(getmypid());
|
||||
Process::signal(SIGTERM, [$this, 'onSignal']);
|
||||
Process::signal(SIGKILL, [$this, 'onSignal']);
|
||||
|
||||
$this->driver->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onSignal($data)
|
||||
{
|
||||
if (!$data) {
|
||||
return;
|
||||
}
|
||||
$this->driver->clear();
|
||||
$pid = file_get_contents(storage('.swoole.pid'));
|
||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
||||
Process::kill($pid, SIGTERM);
|
||||
}
|
||||
if ($this->process && Process::kill($this->process->pid, 0)) {
|
||||
Process::kill($this->process->pid) && Process::wait(true);
|
||||
}
|
||||
while ($ret = Process::wait(true)) {
|
||||
echo "PID={$ret['pid']}\n";
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $message
|
||||
* @param $file
|
||||
* @param $line
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onErrorHandler($code, $message, $file, $line)
|
||||
{
|
||||
if (str_contains($message, 'The file descriptor is not an inotify instance')) {
|
||||
return;
|
||||
}
|
||||
debug('Error:' . $message . ' at ' . $file . ':' . $line);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重启
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function trigger_reload()
|
||||
{
|
||||
$this->logger->warning('change reload');
|
||||
$pid = $this->process?->pid;
|
||||
$process = new Process(function (Process $process) {
|
||||
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
|
||||
});
|
||||
$process->start();
|
||||
if ($pid && Process::kill($pid, 0)) {
|
||||
Process::kill($pid) && Process::wait(true);
|
||||
}
|
||||
$this->process = null;
|
||||
$this->process = $process;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Kiri\FileListen;
|
||||
|
||||
use Exception;
|
||||
use Swoole\Event;
|
||||
use Swoole\Timer;
|
||||
|
||||
class Inotify
|
||||
{
|
||||
@@ -13,14 +14,20 @@ class Inotify
|
||||
|
||||
private array $watchFiles = [];
|
||||
|
||||
|
||||
protected bool $isReloading = FALSE;
|
||||
|
||||
|
||||
protected int $cid;
|
||||
|
||||
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
|
||||
|
||||
|
||||
/**
|
||||
* @param array $dirs
|
||||
* @param FileChangeCustomProcess $process
|
||||
* @param HotReload $process
|
||||
*/
|
||||
public function __construct(protected array $dirs, public FileChangeCustomProcess $process)
|
||||
public function __construct(protected array $dirs, public HotReload $process)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,22 +48,26 @@ class Inotify
|
||||
}
|
||||
|
||||
|
||||
public function clear()
|
||||
{
|
||||
Event::del($this->inotify);
|
||||
Event::exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开始监听
|
||||
* @throws Exception
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
if (!($events = inotify_read($this->inotify))) {
|
||||
return;
|
||||
}
|
||||
if ($this->process->isReloading) {
|
||||
if (!$this->process->isReloadingOut) {
|
||||
$this->process->isReloadingOut = true;
|
||||
}
|
||||
if ($this->isReloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
$LISTEN_TYPE = [IN_CREATE, IN_DELETE, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM];
|
||||
foreach ($events as $ev) {
|
||||
if (!in_array($ev['mask'], $LISTEN_TYPE)) {
|
||||
@@ -64,12 +75,8 @@ class Inotify
|
||||
}
|
||||
//非重启类型
|
||||
if (str_ends_with($ev['name'], '.php')) {
|
||||
if ($this->process->int !== -1) {
|
||||
return;
|
||||
}
|
||||
$this->process->int = @swoole_timer_after(2000, [$this, 'reload']);
|
||||
|
||||
$this->process->isReloading = true;
|
||||
Timer::after(3000, fn()=>$this->reload());
|
||||
$this->isReloading = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,16 +86,13 @@ class Inotify
|
||||
*/
|
||||
public function reload()
|
||||
{
|
||||
$this->process->isReloading = true;
|
||||
$this->process->trigger_reload();
|
||||
|
||||
$this->clearWatch();
|
||||
foreach ($this->dirs as $root) {
|
||||
$this->watch($root);
|
||||
}
|
||||
$this->process->int = -1;
|
||||
$this->process->isReloading = FALSE;
|
||||
$this->process->isReloadingOut = FALSE;
|
||||
$this->isReloading = FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +147,6 @@ class Inotify
|
||||
} else if (!str_ends_with($f, '.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//检测文件类型
|
||||
if (strstr($f, '.') == '.php') {
|
||||
$wd = @inotify_add_watch($this->inotify, $path, $this->events);
|
||||
|
||||
@@ -11,9 +11,9 @@ class Scaner
|
||||
|
||||
/**
|
||||
* @param array $dirs
|
||||
* @param FileChangeCustomProcess $process
|
||||
* @param HotReload $process
|
||||
*/
|
||||
public function __construct(protected array $dirs, public FileChangeCustomProcess $process)
|
||||
public function __construct(protected array $dirs, public HotReload $process)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ class Scaner
|
||||
*/
|
||||
public function timerReload()
|
||||
{
|
||||
if ($this->process->isReloading) {
|
||||
return;
|
||||
}
|
||||
$this->process->isReloading = true;
|
||||
$this->process->trigger_reload();
|
||||
|
||||
@@ -117,12 +120,20 @@ class Scaner
|
||||
}
|
||||
|
||||
|
||||
private bool $isStop = false;
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->isStop = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function tick()
|
||||
{
|
||||
if ($this->process->isReloading) {
|
||||
if ($this->process->isReloading || $this->isStop) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ defined('TASK_PATH') or define('TASK_PATH', APP_PATH . 'app/Async/');
|
||||
defined('LISTENER_PATH') or define('LISTENER_PATH', APP_PATH . 'app/Listener/');
|
||||
defined('KAFKA_PATH') or define('KAFKA_PATH', APP_PATH . 'app/Kafka/');
|
||||
defined('RPC_CLIENT_PATH') or define('RPC_CLIENT_PATH', APP_PATH . 'app/Client/Rpc/');
|
||||
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Models/');
|
||||
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Model/');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -220,6 +220,13 @@ class Pool extends Component
|
||||
return;
|
||||
}
|
||||
while (static::$_connections[$name]->length() > 0) {
|
||||
if (static::$_connections[$name] instanceof Channel)
|
||||
{
|
||||
if (!Context::inCoroutine())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
$client = static::$_connections[$name]->pop();
|
||||
if ($client instanceof StopHeartbeatCheck) {
|
||||
$client->stopHeartbeatCheck();
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Proxy;
|
||||
|
||||
abstract class AProxy
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Proxy;
|
||||
|
||||
use Annotation\Aspect;
|
||||
use Http\Handler\Handler;
|
||||
use Kiri\Di\NoteManager;
|
||||
use Kiri\IAspect;
|
||||
use Kiri\Kiri;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class AspectProxy extends AProxy implements ProxyInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Handler $executor
|
||||
* @return mixed
|
||||
*/
|
||||
public function proxy(Handler $executor): mixed
|
||||
{
|
||||
if ($executor->callback instanceof \Closure) {
|
||||
return call_user_func($executor->callback, ...$executor->params);
|
||||
}
|
||||
$controller = Kiri::getDi()->get($executor->callback[0]);
|
||||
$aspect = $this->getAspect($executor->callback);
|
||||
if (!is_null($aspect)) {
|
||||
$aspect->before();
|
||||
$result = $aspect->invoke([$controller, $executor->callback[1]], $executor->params);
|
||||
$aspect->after($result);
|
||||
} else {
|
||||
$result = call_user_func([$controller, $executor->callback[1]]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $executor
|
||||
* @return ?IAspect
|
||||
*/
|
||||
protected function getAspect(array $executor): ?IAspect
|
||||
{
|
||||
$aspect = NoteManager::getSpecify_annotation(Aspect::class, $executor[0], $executor[1]);
|
||||
if (!is_null($aspect)) {
|
||||
$aspect = Kiri::getDi()->get($aspect->aspect);
|
||||
}
|
||||
return $aspect;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Proxy;
|
||||
|
||||
use Http\Handler\Handler;
|
||||
|
||||
interface ProxyInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Handler $executor
|
||||
* @return mixed
|
||||
*/
|
||||
public function proxy(Handler $executor): mixed;
|
||||
|
||||
}
|
||||
+4
-4
@@ -30,11 +30,11 @@ class Gii
|
||||
|
||||
private InputInterface $input;
|
||||
|
||||
public string $modelPath = APP_PATH . 'app/Models/';
|
||||
public string $modelNamespace = 'App\\Models\\';
|
||||
public string $modelPath = APP_PATH . 'app/Model/';
|
||||
public string $modelNamespace = 'App\\Model\\';
|
||||
|
||||
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
|
||||
public string $controllerNamespace = 'App\\Controllers\\';
|
||||
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
|
||||
public string $controllerNamespace = 'App\\Controller\\';
|
||||
|
||||
|
||||
public static array $createSqls = [];
|
||||
|
||||
@@ -24,11 +24,11 @@ abstract class GiiBase
|
||||
|
||||
protected InputInterface $input;
|
||||
|
||||
public string $modelPath = APP_PATH . 'app/Models/';
|
||||
public string $modelNamespace = 'App\Models\\';
|
||||
public string $modelPath = APP_PATH . 'app/Model/';
|
||||
public string $modelNamespace = 'App\Model\\';
|
||||
|
||||
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
|
||||
public string $controllerNamespace = 'App\\Controllers\\';
|
||||
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
|
||||
public string $controllerNamespace = 'App\\Controller\\';
|
||||
|
||||
public ?string $module = null;
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ use Kiri\Core\Json;
|
||||
use Database\Connection;
|
||||
use Database\Annotation\Get;
|
||||
use Database\Annotation\Set;
|
||||
use Annotation\Model\Relation;
|
||||
use Database\Relation;
|
||||
use Database\Model;
|
||||
' . PHP_EOL;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class GiiTask extends GiiBase
|
||||
|
||||
namespace App\Async;
|
||||
|
||||
use Server\SInterface\OnTaskInterface;
|
||||
use Server\Contract\OnTaskInterface;
|
||||
|
||||
';
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Process;
|
||||
|
||||
interface OnProcessInterface
|
||||
{
|
||||
|
||||
public function handle();
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Process;
|
||||
|
||||
abstract class Process implements OnProcessInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var \Swoole\Process
|
||||
*/
|
||||
protected \Swoole\Process $process;
|
||||
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected mixed $redirect_stdin_and_stdout = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $pipe_type = SOCK_DGRAM;
|
||||
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $enable_coroutine = true;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $name = '';
|
||||
|
||||
/**
|
||||
* @return \Swoole\Process
|
||||
*/
|
||||
public function getProcess(): \Swoole\Process
|
||||
{
|
||||
return $this->process;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRedirectStdinAndStdout(): mixed
|
||||
{
|
||||
return $this->redirect_stdin_and_stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPipeType(): int
|
||||
{
|
||||
return $this->pipe_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnableCoroutine(): bool
|
||||
{
|
||||
return $this->enable_coroutine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
*/
|
||||
public function start(\Swoole\Process $process)
|
||||
{
|
||||
$this->process = $process;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kiri\Process;
|
||||
|
||||
require_once 'OnProcessInterface.php';
|
||||
require_once 'Process.php';
|
||||
|
||||
use function Co\run;
|
||||
|
||||
class TestProcess extends Process
|
||||
{
|
||||
|
||||
|
||||
protected string $name = 'test process';
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onStart()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// TODO: Implement doWhile() method.
|
||||
}
|
||||
|
||||
|
||||
public function onShutdown()
|
||||
{
|
||||
// TODO: Implement onShutdown() method.
|
||||
}
|
||||
}
|
||||
|
||||
$array = [];
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$class = new TestProcess();
|
||||
$process = new \Swoole\Process([$class, 'start'], $class->getRedirectStdinAndStdout(),
|
||||
$class->getPipeType(), $class->isEnableCoroutine());
|
||||
$process->start();
|
||||
|
||||
array_push($array, $process);
|
||||
}
|
||||
run(function () use ($array) {
|
||||
|
||||
foreach ($array as $value) {
|
||||
var_dump($value->getCallback());
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user