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