modify plugin name

This commit is contained in:
2022-02-23 18:12:57 +08:00
parent 1cdb8aceac
commit 09dd2443c7
3 changed files with 11 additions and 10 deletions
+4 -4
View File
@@ -5,7 +5,6 @@ namespace Kiri\FileListen;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Annotation\Inject;
use Kiri\Core\Json; use Kiri\Core\Json;
use Kiri\Error\StdoutLoggerInterface; use Kiri\Error\StdoutLoggerInterface;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
@@ -39,7 +38,6 @@ class HotReload extends Command
public Inotify|Scaner $driver; public Inotify|Scaner $driver;
#[Inject(StdoutLoggerInterface::class)]
public StdoutLoggerInterface $logger; public StdoutLoggerInterface $logger;
@@ -55,6 +53,8 @@ class HotReload extends Command
protected function configure() protected function configure()
{ {
$this->setName('sw:wather')->setDescription('server start'); $this->setName('sw:wather')->setDescription('server start');
$this->logger = Kiri::getDi()->get(StdoutLoggerInterface::class);
} }
@@ -67,9 +67,9 @@ class HotReload extends Command
set_error_handler([$this, 'errorHandler']); set_error_handler([$this, 'errorHandler']);
$this->dirs = Config::get('inotify', [APP_PATH . 'app']); $this->dirs = Config::get('inotify', [APP_PATH . 'app']);
if (!extension_loaded('inotify')) { if (!extension_loaded('inotify')) {
$this->driver = Kiri::getDi()->make(Scaner::class, [$this->dirs, $this]); $this->driver = make(Scaner::class, [$this->dirs, $this, $this->logger]);
} else { } else {
$this->driver = Kiri::getDi()->make(Inotify::class, [$this->dirs, $this]); $this->driver = make(Inotify::class, [$this->dirs, $this, $this->logger]);
} }
$this->clearOtherService(); $this->clearOtherService();
$this->setProcessName(); $this->setProcessName();
+5 -4
View File
@@ -27,8 +27,10 @@ class Inotify
/** /**
* @param array $dirs * @param array $dirs
* @param HotReload $process * @param HotReload $process
* @param StdoutLoggerInterface $logger
*
*/ */
public function __construct(protected array $dirs, public HotReload $process) public function __construct(protected array $dirs, public HotReload $process, public StdoutLoggerInterface $logger)
{ {
set_error_handler([$this, 'error']); set_error_handler([$this, 'error']);
set_exception_handler([$this, 'error']); set_exception_handler([$this, 'error']);
@@ -103,7 +105,7 @@ class Inotify
*/ */
public function reload($path) public function reload($path)
{ {
\Kiri::getDi()->get(StdoutLoggerInterface::class)->warning('file change'); $this->logger->warning('file change');
$this->process->trigger_reload($path); $this->process->trigger_reload($path);
$this->process->int = -1; $this->process->int = -1;
@@ -137,8 +139,7 @@ class Inotify
{ {
//目录不存在 //目录不存在
if (!is_dir($dir)) { if (!is_dir($dir)) {
logger()->addError("[$dir] is not a directory."); return $this->logger->addError("[$dir] is not a directory.");
return false;
} }
//避免重复监听 //避免重复监听
if (isset($this->watchFiles[$dir])) { if (isset($this->watchFiles[$dir])) {
+2 -2
View File
@@ -17,7 +17,7 @@ class Scaner
* @param array $dirs * @param array $dirs
* @param HotReload $process * @param HotReload $process
*/ */
public function __construct(protected array $dirs, public HotReload $process) public function __construct(protected array $dirs, public HotReload $process, public StdoutLoggerInterface $logger)
{ {
} }
@@ -113,7 +113,7 @@ class Scaner
{ {
$this->isReloading = TRUE; $this->isReloading = TRUE;
\Kiri::getDi()->get(StdoutLoggerInterface::class)->warning('file change'); $this->logger->warning('file change');
$this->process->trigger_reload($path); $this->process->trigger_reload($path);