modify plugin name
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Kiri\Reload;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Exception;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Annotation\Inject;
|
||||
use Kiri\Server\Abstracts\BaseProcess;
|
||||
use Kiri\Server\ServerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Swoole\Process;
|
||||
|
||||
@@ -46,59 +48,51 @@ class Scaner extends BaseProcess
|
||||
private function loadDirs(bool $isReload = FALSE)
|
||||
{
|
||||
foreach ($this->dirs as $value) {
|
||||
if (is_bool($path = realpath($value))) {
|
||||
$value = new DirectoryIterator($value);
|
||||
if ($value->isDot() || str_starts_with($value->getFilename(), '.')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_dir($path)) continue;
|
||||
|
||||
$this->loadByDir($path, $isReload);
|
||||
if ($value->isDir()) {
|
||||
$this->loadByDir($value, $isReload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param DirectoryIterator $path
|
||||
* @param bool $isReload
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function loadByDir($path, bool $isReload = FALSE): void
|
||||
private function loadByDir(DirectoryIterator $path, bool $isReload = FALSE): void
|
||||
{
|
||||
if (!is_string($path)) {
|
||||
if ($path->isDir()) {
|
||||
$this->loadByDir(new DirectoryIterator($path->getRealPath()), $isReload);
|
||||
}
|
||||
if (!str_ends_with($path->getFilename(), '.php')) {
|
||||
return;
|
||||
}
|
||||
$path = rtrim($path, '/');
|
||||
foreach (glob(realpath($path) . '/*') as $value) {
|
||||
if (is_dir($value)) {
|
||||
$this->loadByDir($value, $isReload);
|
||||
}
|
||||
if (is_file($value)) {
|
||||
if ($this->checkFile($value, $isReload)) {
|
||||
if ($this->checkFile($path, $isReload)) {
|
||||
if ($this->isReloading) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
$this->isReloading = TRUE;
|
||||
|
||||
sleep(2);
|
||||
|
||||
$this->timerReload();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param DirectoryIterator $value
|
||||
* @param $isReload
|
||||
* @return bool
|
||||
*/
|
||||
private function checkFile($value, $isReload): bool
|
||||
private function checkFile(DirectoryIterator $value, $isReload): bool
|
||||
{
|
||||
$md5 = md5($value);
|
||||
$mTime = filectime($value);
|
||||
$md5 = md5_file($value->getRealPath());
|
||||
$mTime = $value->getCTime();
|
||||
if (!isset($this->md5Map[$md5])) {
|
||||
if ($isReload) {
|
||||
return TRUE;
|
||||
@@ -125,7 +119,7 @@ class Scaner extends BaseProcess
|
||||
|
||||
$this->logger->warning('file change');
|
||||
|
||||
$swow = \Kiri::getDi()->get(SwooleServerInterface::class);
|
||||
$swow = \Kiri::getDi()->get(ServerInterface::class);
|
||||
|
||||
$swow->reload();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user