From b782fae56210ef6bab3a609175b385bcff0977c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 16 Apr 2023 16:40:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Main.php | 9 ++-- kiri-engine/Scanner.php | 104 ---------------------------------------- 2 files changed, 4 insertions(+), 109 deletions(-) delete mode 100644 kiri-engine/Scanner.php diff --git a/kiri-engine/Main.php b/kiri-engine/Main.php index 4fcbb2dd..2794a635 100644 --- a/kiri-engine/Main.php +++ b/kiri-engine/Main.php @@ -12,8 +12,10 @@ namespace Kiri; use Exception; use Kiri; -use Kiri\Di\Container; use Kiri\Abstracts\{BaseMain, Config, Kernel}; +use Kiri\Di\LocalService; +use Kiri\Di\Scanner; +use Kiri\Error\ErrorHandler; use Kiri\Events\{OnAfterCommandExecute, OnBeforeCommandExecute}; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -21,10 +23,7 @@ use ReflectionException; use Symfony\Component\Console\{Application as ConsoleApplication, Input\ArgvInput, Output\ConsoleOutput, - Output\OutputInterface -}; -use Kiri\Di\LocalService; -use Kiri\Error\ErrorHandler; + Output\OutputInterface}; /** diff --git a/kiri-engine/Scanner.php b/kiri-engine/Scanner.php deleted file mode 100644 index ad3981b6..00000000 --- a/kiri-engine/Scanner.php +++ /dev/null @@ -1,104 +0,0 @@ -load_dir($path); - } - - - /** - * @param string $namespace - * @return void - * @throws ReflectionException - * @throws Exception - */ - public function parse(string $namespace): void - { - $container = Container::instance(); - foreach ($this->files as $file) { - $class = $namespace . '\\' . $this->rename($file); - if (file_exists($class)) { - error('Please follow the PSR-4 specification to write code.' . $class); - continue; - } - $container->parse($class); - } - } - - - /** - * @param string $file - * @return string - */ - private function rename(string $file): string - { - $filter = array_filter(explode('/', $file), function ($value) { - if (empty($value)) { - return false; - } - return ucfirst($value); - }); - array_shift($filter); - return implode('\\', $filter); - } - - - /** - * @param string $path - * @return void - */ - private function load_dir(string $path): void - { - $dir = new \DirectoryIterator($path); - foreach ($dir as $value) { - if ($value->isDot()) { - continue; - } - if ($value->isDir()) { - $this->load_dir($value->getRealPath()); - } else if ($value->getExtension() == '.php') { - $this->load_file($value); - } - } - } - - - /** - * @param string $path - * @return void - */ - private function load_file(string $path): void - { - try { - require_once "$path"; - $path = str_replace($_SERVER['HOME'], '', $path); - $path = str_replace('.php', '', $path); - $this->files[] = $path; - } catch (\Throwable $throwable) { - error($throwable->getMessage(), [$throwable]); - } - } - - -}