Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7db58d7e4 | |||
| 87e4bfdbec | |||
| ee761817bf | |||
| 4a4b7db651 | |||
| 905427bccc | |||
| 68ee0244a2 |
+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": {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Kiri\FileListen;
|
||||
|
||||
use Exception;
|
||||
use Swoole\Event;
|
||||
use Swoole\Timer;
|
||||
|
||||
class Inotify
|
||||
{
|
||||
@@ -14,6 +15,9 @@ class Inotify
|
||||
private array $watchFiles = [];
|
||||
|
||||
|
||||
protected bool $isReloading = FALSE;
|
||||
|
||||
|
||||
protected int $cid;
|
||||
|
||||
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
|
||||
@@ -60,7 +64,7 @@ class Inotify
|
||||
if (!($events = inotify_read($this->inotify))) {
|
||||
return;
|
||||
}
|
||||
if ($this->process->isReloading) {
|
||||
if ($this->isReloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,7 +75,8 @@ class Inotify
|
||||
}
|
||||
//非重启类型
|
||||
if (str_ends_with($ev['name'], '.php')) {
|
||||
$this->reload();
|
||||
Timer::after(3000, fn()=>$this->reload());
|
||||
$this->isReloading = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,19 +86,13 @@ class Inotify
|
||||
*/
|
||||
public function reload()
|
||||
{
|
||||
if ($this->process->isReloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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->isReloading = FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user