diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 0f82d0e5..5fd517bf 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -465,7 +465,7 @@ class Server extends HttpService $router = Snowflake::app()->getRouter(); $router->loadRouterSetting(); - recursive_directory(SOCKET_PATH, [$this, 'recursive_callback']); + recursive_directory(SOCKET_PATH); }); } @@ -477,35 +477,11 @@ class Server extends HttpService { $event = Snowflake::app()->getEvent(); $event->on(Event::SERVER_WORKER_START, function () { - recursive_directory(SOCKET_PATH, [$this, 'recursive_callback']); + recursive_directory(SOCKET_PATH); }); } - /** - * @param DirectoryIterator $file - * @throws ComponentException - * @throws NotFindClassException - * @throws ReflectionException - */ - public function recursive_callback(DirectoryIterator $file) - { - $attributes = Snowflake::app()->getAttributes(); - - $annotations = $attributes->getFilename($file->getRealPath()); - if (empty($annotations)) { - return; - } - - /** @var Attribute $attribute */ - foreach ($annotations['methods'] as $name => $attribute) { - if (!($attribute instanceof Attribute)) { - continue; - } - $attribute->execute([$annotations['handler'], $name]); - } - } - /** * @param $type diff --git a/function.php b/function.php index 8f170e2a..d5d90678 100644 --- a/function.php +++ b/function.php @@ -10,6 +10,7 @@ use HttpServer\Http\Response; use HttpServer\Route\Router; use Snowflake\Error\Logger; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; use HttpServer\Http\Context; use Snowflake\Core\ArrayAccess; @@ -69,10 +70,33 @@ if (!function_exists('recursive_directory')) { /** - * @param string $path - * @param array|Closure $callback + * @param DirectoryIterator $file + * @throws ComponentException + * @throws ReflectionException + * @throws NotFindClassException */ - function recursive_directory(string $path, array|Closure $callback) + function recursive_callback(DirectoryIterator $file) + { + $attributes = Snowflake::app()->getAttributes(); + + $annotations = $attributes->getFilename($file->getRealPath()); + if (empty($annotations)) { + return; + } + + /** @var Attribute $attribute */ + foreach ($annotations['methods'] as $name => $attribute) { + if (!($attribute instanceof Attribute)) { + continue; + } + $attribute->execute([$annotations['handler'], $name]); + } + } + + /** + * @param string $path + */ + function recursive_directory(string $path) { $directoryIterators = new \DirectoryIterator($path); foreach ($directoryIterators as $directoryIterator) { @@ -80,9 +104,9 @@ if (!function_exists('recursive_directory')) { continue; } if ($directoryIterator->isDir()) { - Recursive_directory($directoryIterator->getRealPath(), $callback); + Recursive_directory($directoryIterator->getRealPath()); } else { - call_user_func($callback, $directoryIterator); + call_user_func('recursive_callback', $directoryIterator); } } unset($directoryIterators);