From 7b1cc1bd7b26b9348aab941686eaaef681e281d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 12 Jan 2022 14:10:33 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=94=B9=E5=90=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fdf58326 --- kiri-engine/Kiri.php => Kiri.php | 1278 +++++++++-------- composer.json | 1 + function.php | 1 - kiri-annotation/Event.php | 2 +- kiri-annotation/Inject.php | 2 +- kiri-annotation/Loader.php | 2 +- kiri-annotation/Mapping.php | 2 +- kiri-annotation/Route/Route.php | 2 +- kiri-annotation/Task.php | 2 +- kiri-engine/Abstracts/BaseApplication.php | 2 +- kiri-engine/Abstracts/Component.php | 4 +- kiri-engine/Abstracts/Config.php | 2 +- kiri-engine/Abstracts/Configure.php | 2 +- kiri-engine/Abstracts/Logger.php | 2 +- kiri-engine/Application.php | 2 + kiri-engine/Async.php | 2 +- kiri-engine/Cache/Base/Redis.php | 2 +- kiri-engine/Cache/File.php | 2 +- kiri-engine/Cache/ICache.php | 2 +- kiri-engine/Cache/Redis.php | 4 +- kiri-engine/Context.php | 2 +- kiri-engine/Core/DateFormat.php | 2 +- kiri-engine/Core/Help.php | 2 +- kiri-engine/Core/Json.php | 2 +- kiri-engine/Core/Reader.php | 2 +- kiri-engine/Core/Str.php | 2 +- kiri-engine/Core/Xml.php | 2 +- kiri-engine/Di/Container.php | 75 +- kiri-engine/Di/LocalService.php | 2 +- kiri-engine/Environmental.php | 2 +- kiri-engine/Error/ErrorHandler.php | 4 +- kiri-engine/Error/ErrorInterface.php | 2 +- kiri-engine/Error/Logger.php | 4 +- kiri-engine/Error/LoggerAspect.php | 2 +- kiri-engine/Error/LoggerProcess.php | 2 +- kiri-engine/Event.php | 2 +- kiri-engine/Exception/ComponentException.php | 2 +- .../Exception/NotFindClassException.php | 2 +- .../Exception/NotFindPropertyException.php | 2 +- kiri-engine/FileListen/HotReload.php | 2 +- kiri-engine/Pool/Connection.php | 2 +- kiri-engine/Pool/Redis.php | 4 +- kiri-engine/Runtime.php | 2 +- kiri-gii/Gii.php | 2 +- kiri-gii/GiiCommand.php | 2 +- kiri-gii/GiiController.php | 2 +- kiri-gii/GiiMiddleware.php | 2 +- kiri-gii/GiiModel.php | 2 +- kiri-gii/GiiProviders.php | 2 +- kiri-gii/GiiRpcClient.php | 4 +- kiri-gii/GiiRpcService.php | 2 +- kiri-gii/GiiTask.php | 2 +- kiri-websocket-server/Sender.php | 2 +- 53 files changed, 739 insertions(+), 726 deletions(-) rename kiri-engine/Kiri.php => Kiri.php (94%) diff --git a/kiri-engine/Kiri.php b/Kiri.php similarity index 94% rename from kiri-engine/Kiri.php rename to Kiri.php index e5ee0008..11ab0db9 100644 --- a/kiri-engine/Kiri.php +++ b/Kiri.php @@ -1,636 +1,642 @@ -setBindings(ContainerInterface::class, $container); - static::$container = $container; - } - - - /** - * @param $alias - * @param array $array - * @throws Exception - */ - public static function set($alias, array $array = []) - { - static::app()->set($alias, $array); - } - - - /** - * @param string $name - * @return mixed - * @throws Exception - */ - public static function getApp(string $name): mixed - { - return static::app()->get($name); - } - - /** - * @return Application|null - */ - public static function app(): ?Application - { - return static::$service; - } - - - /** - * @return Application|null - */ - public static function getFactory(): ?Application - { - return static::$service; - } - - - /** - * @return Application|null - */ - public static function getApplicationContext(): ?Application - { - return static::$service; - } - - - /** - * @return Container|null - */ - public static function getContainerContext(): ?Container - { - return static::$container; - } - - /** - * @param $name - * @return bool - */ - public static function has($name): bool - { - return static::$service->has($name); - } - - - /** - * @param $port - * @return bool - * @throws Exception - */ - public static function port_already($port): bool - { - if (empty($port)) { - return false; - } - if (Kiri::getPlatform()->isLinux()) { - exec('netstat -tunlp | grep ' . $port, $output); - } else { - exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output); - } - return !empty($output); - } - - - /** - * @return Annotation - * @throws Exception - */ - public static function getAnnotation(): Annotation - { - return static::app()->getAnnotation(); - } - - - /** - * @param $service - * @return string - */ - #[Pure] public static function listen($service): string - { - return sprintf('Check listen %s::%d -> ok', $service['host'], $service['port']); - } - - - /** - * @param $className - * @param array $construct - * @return mixed - * @throws Exception - */ - public static function createObject($className, array $construct = []): mixed - { - if (is_string($className) && class_exists($className)) { - return static::$container->get($className, $construct); - } else if (is_array($className) && isset($className['class'])) { - $class = $className['class']; - unset($className['class']); - return static::$container->create($class, $construct, $className); - } else if (is_callable($className, TRUE)) { - return call_user_func($className, $construct); - } else { - throw new Exception('Unsupported configuration type: ' . gettype($className)); - } - } - - /** - * @return string - * @throws Exception - */ - public static function getStoragePath(): string - { - $default = APP_PATH . 'storage' . DIRECTORY_SEPARATOR; - $path = Config::get('storage', $default); - if (!is_dir($path)) { - mkdir($path, 0777, true); - } - return $path; - } - - - /** - * @return bool - */ - public static function inCoroutine(): bool - { - return Coroutine::getCid() > 0; - } - - - /** - * @return Container - */ - public static function getDi(): Container - { - return static::$container; - } - - - /** - * @return Container - */ - public static function di(): Container - { - return static::$container; - } - - - /** - * @param $workerId - * @return mixed - * @throws Exception - */ - public static function setManagerId($workerId): mixed - { - if (empty($workerId) || static::isDocker()) { - return $workerId; - } - - $tmpFile = storage($workerId . '.sock', 'pid/manager'); - - return self::writeFile($tmpFile, $workerId); - } - - - /** - * @param $workerId - * @return mixed - * @throws Exception - */ - public static function setProcessId($workerId): mixed - { - if (empty($workerId) || static::isDocker()) { - return $workerId; - } - - $tmpFile = storage($workerId . '.sock', 'pid/process'); - - return self::writeFile($tmpFile, $workerId); - } - - - /** - * @return bool - */ - public static function isDocker(): bool - { - $output = shell_exec('[ -f /.dockerenv ] && echo yes || echo no'); - if (trim($output) === 'yes') { - return true; - } - return false; - } - - - /** - * @param $workerId - * @return mixed - * @throws Exception - */ - public static function setWorkerId($workerId): mixed - { - if (empty($workerId) || static::isDocker()) { - return $workerId; - } - - $tmpFile = storage($workerId . '.sock', 'pid/worker'); - - return self::writeFile($tmpFile, $workerId); - } - - - /** - * @param $workerId - * @return mixed - * @throws Exception - */ - public static function setTaskId($workerId): mixed - { - if (empty($workerId) || static::isDocker()) { - return $workerId; - } - - $tmpFile = storage($workerId . '.sock', 'pid/task'); - - return self::writeFile($tmpFile, $workerId); - } - - /** - * @param $fileName - * @param $content - * @param null $is_append - * @return mixed - */ - public static function writeFile($fileName, $content, $is_append = null): mixed - { - $params = [$fileName, (string)$content]; - if ($is_append !== null) { - $params[] = $is_append; - } - return !self::inCoroutine() ? file_put_contents(...$params) : Coroutine::writeFile(...$params); - } - - - /** - * @param $object - * @param $config - * @return mixed - */ - public static function configure($object, $config): mixed - { - foreach ($config as $key => $value) { - if (!property_exists($object, $key)) { - continue; - } - $object->$key = $value; - } - return $object; - } - - - /** - * @param $workerId - * @param bool $isWorker - * @throws Exception - */ - public static function clearProcessId($workerId, bool $isWorker = false) - { - clearstatcache(); - $directory = $isWorker === true ? 'pid/worker' : 'pid/task'; - if (!file_exists($file = storage($workerId, $directory))) { - return; - } - shell_exec('rm -rf ' . $file); - } - - - /** - * @param string|null $taskPid - * @throws Exception - */ - public static function clearTaskPid(string $taskPid = null) - { - if (empty($taskPid)) { - exec('rm -rf ' . storage(null, 'pid/task')); - } else { - static::clearProcessId($taskPid); - } - } - - - /** - * @param $taskPid - * @throws Exception - */ - public static function clearWorkerPid($taskPid = null) - { - if (empty($taskPid)) { - exec('rm -rf ' . storage(null, 'pid/worker')); - } else { - static::clearProcessId($taskPid, true); - } - } - - - /** - * @return Server|null - * @throws - */ - public static function getWebSocket(): ?\Swoole\Server - { - $server = static::app()->getSwoole(); - if (!($server instanceof \Swoole\Server)) { - return null; - } - return $server; - } - - - /** - * @return false|string - * @throws Exception - */ - public static function getMasterPid(): bool|string - { - $pid = Kiri::app()->getSwoole()->setting['pid_file']; - - return file_get_contents($pid); - } - - - /** - * @param int $fd - * @param $data - * @return mixed - * @throws Exception - */ - public static function push(int $fd, $data): mixed - { - $server = static::getWebSocket(); - if (empty($server) || !$server->isEstablished($fd)) { - return false; - } - if (!is_string($data)) { - $data = Json::encode($data); - } - return $server->push($fd, $data); - } - - - /** - * @return mixed - */ - public static function localhost(): mixed - { - return current(swoole_get_local_ip()); - } - - - /** - * @param string $class - * @param array $params - * @throws ReflectionException - * @throws Exception - */ - public static function async(string $class, array $params = []) - { - $manager = di(AsyncTaskExecute::class); - $manager->execute(new $class(...$params)); - } - - - /** - * @param array $v1 - * @param array $v2 - * @return float - */ - #[Pure] public static function distance(array $v1, array $v2): float - { - $maxX = max($v1['x'], $v2['x']); - $minX = min($v1['x'], $v2['x']); - - $maxZ = max($v1['z'], $v2['z']); - $minZ = min($v1['z'], $v2['z']); - - $dx = abs($maxX - $minX); - $dy = abs($maxZ - $minZ); - - $sqrt = sqrt($dx * $dx + $dy * $dy); - if ($sqrt < 0) { - $sqrt = abs($sqrt); - } - return (float)$sqrt; - } - - - /** - * @param $process - * @throws Exception - */ - public static function shutdown($process): void - { - static::app()->getSwoole()->shutdown(); - if ($process instanceof Process) { - $process->exit(0); - } - } - - - /** - * @param $tmp_name - * @return string - */ - public static function rename($tmp_name): string - { - $hash = md5_file($tmp_name); - - $later = '.' . exif_imagetype($tmp_name); - - $match = '/(\w{12})(\w{5})(\w{9})(\w{6})/'; - $tmp = preg_replace($match, '$1-$2-$3-$4', $hash); - - return strtoupper($tmp) . $later; - } - - - /** - * @return Environmental - * @throws - */ - public static function getPlatform(): Environmental - { - return Kiri::createObject(Environmental::class); - } - - - /** - * @return mixed - * @throws Exception - */ - public static function reload(): mixed - { - return Kiri::app()->getSwoole()->reload(); - } - - - private static array $_autoload = []; - - - const PROCESS = 'process'; - const TASK = 'task'; - const WORKER = 'worker'; - - - /** - * @param string $event - * @param null $data - * @return false|string - * @throws Exception - */ - public static function param(string $event, $data = NULL): bool|string - { - if (is_object($data)) { - if ($data instanceof ModelInterface || $data instanceof Collection) { - $data = $data->getAttributes(); - } else { - $data = get_object_vars($data); - } - } - if (!is_array($data)) $data = ['data' => $data]; - return json_encode(array_merge(['callback' => $event], $data)); - } - - - /** - * @return string|null - */ - #[Pure] public static function getEnvironmental(): ?string - { - return env('environmental'); - } - - - /** - * @return bool - */ - #[Pure] public static function isTask(): bool - { - return static::getEnvironmental() == static::TASK; - } - - - /** - * @return bool - */ - #[Pure] public static function isWorker(): bool - { - return static::getEnvironmental() == static::WORKER; - } - - - /** - * @return bool - */ - #[Pure] public static function isProcess(): bool - { - return static::getEnvironmental() == static::PROCESS; - } - - - /** - * @param $class - * @param $file - */ - public static function setAutoload($class, $file) - { - if (isset(static::$_autoload[$class])) { - return; - } - static::$_autoload[$class] = $file; - include_once "Kiri.php"; - } - - - /** - * @param $className - */ - public static function autoload($className) - { - if (!isset(static::$_autoload[$className])) { - return; - } - $file = static::$_autoload[$className]; - require_once "Kiri.php"; - } - - -} - -//spl_autoload_register([Kiri::class, 'autoload'], true, true); -Kiri::setContainer(new Container()); +setBindings(ContainerInterface::class, $container); + static::$container = $container; + } + + + /** + * @return Container + */ + public static function getContainer(): Container + { + return static::$container; + } + + + /** + * @param $alias + * @param array $array + * @throws Exception + */ + public static function set($alias, array $array = []) + { + static::app()->set($alias, $array); + } + + + /** + * @param string $name + * @return mixed + * @throws Exception + */ + public static function getApp(string $name): mixed + { + return static::app()->get($name); + } + + /** + * @return Application|null + */ + public static function app(): ?Application + { + return static::$service; + } + + + /** + * @return Application|null + */ + public static function getFactory(): ?Application + { + return static::$service; + } + + + /** + * @return Application|null + */ + public static function getApplicationContext(): ?Application + { + return static::$service; + } + + + /** + * @return Container|null + */ + public static function getContainerContext(): ?Container + { + return static::$container; + } + + /** + * @param $name + * @return bool + */ + public static function has($name): bool + { + return static::$service->has($name); + } + + + /** + * @param $port + * @return bool + * @throws Exception + */ + public static function port_already($port): bool + { + if (empty($port)) { + return false; + } + if (Kiri::getPlatform()->isLinux()) { + exec('netstat -tunlp | grep ' . $port, $output); + } else { + exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output); + } + return !empty($output); + } + + + /** + * @return Annotation + * @throws Exception + */ + public static function getAnnotation(): Annotation + { + return static::app()->getAnnotation(); + } + + + /** + * @param $service + * @return string + */ + #[Pure] public static function listen($service): string + { + return sprintf('Check listen %s::%d -> ok', $service['host'], $service['port']); + } + + + /** + * @param $className + * @param array $construct + * @return mixed + * @throws Exception + */ + public static function createObject($className, array $construct = []): mixed + { + if (is_string($className) && class_exists($className)) { + return static::$container->get($className, $construct); + } else if (is_array($className) && isset($className['class'])) { + $class = $className['class']; + unset($className['class']); + return static::$container->create($class, $construct, $className); + } else if (is_callable($className, TRUE)) { + return call_user_func($className, $construct); + } else { + throw new Exception('Unsupported configuration type: ' . gettype($className)); + } + } + + + /** + * @return string + * @throws Exception + */ + public static function getStoragePath(): string + { + $default = APP_PATH . 'storage' . DIRECTORY_SEPARATOR; + $path = Config::get('storage', $default); + if (!is_dir($path)) { + mkdir($path, 0777, true); + } + return $path; + } + + + /** + * @return bool + */ + public static function inCoroutine(): bool + { + return Coroutine::getCid() > 0; + } + + + /** + * @return Container + */ + public static function getDi(): Container + { + return static::$container; + } + + + /** + * @return Container + */ + public static function di(): Container + { + return static::$container; + } + + + /** + * @param $workerId + * @return mixed + * @throws Exception + */ + public static function setManagerId($workerId): mixed + { + if (empty($workerId) || static::isDocker()) { + return $workerId; + } + + $tmpFile = storage($workerId . '.sock', 'pid/manager'); + + return self::writeFile($tmpFile, $workerId); + } + + + /** + * @param $workerId + * @return mixed + * @throws Exception + */ + public static function setProcessId($workerId): mixed + { + if (empty($workerId) || static::isDocker()) { + return $workerId; + } + + $tmpFile = storage($workerId . '.sock', 'pid/process'); + + return self::writeFile($tmpFile, $workerId); + } + + + /** + * @return bool + */ + public static function isDocker(): bool + { + $output = shell_exec('[ -f /.dockerenv ] && echo yes || echo no'); + if (trim($output) === 'yes') { + return true; + } + return false; + } + + + /** + * @param $workerId + * @return mixed + * @throws Exception + */ + public static function setWorkerId($workerId): mixed + { + if (empty($workerId) || static::isDocker()) { + return $workerId; + } + + $tmpFile = storage($workerId . '.sock', 'pid/worker'); + + return self::writeFile($tmpFile, $workerId); + } + + + /** + * @param $workerId + * @return mixed + * @throws Exception + */ + public static function setTaskId($workerId): mixed + { + if (empty($workerId) || static::isDocker()) { + return $workerId; + } + + $tmpFile = storage($workerId . '.sock', 'pid/task'); + + return self::writeFile($tmpFile, $workerId); + } + + /** + * @param $fileName + * @param $content + * @param null $is_append + * @return mixed + */ + public static function writeFile($fileName, $content, $is_append = null): mixed + { + $params = [$fileName, (string)$content]; + if ($is_append !== null) { + $params[] = $is_append; + } + return !self::inCoroutine() ? file_put_contents(...$params) : Coroutine::writeFile(...$params); + } + + + /** + * @param $object + * @param $config + * @return mixed + */ + public static function configure($object, $config): mixed + { + foreach ($config as $key => $value) { + if (!property_exists($object, $key)) { + continue; + } + $object->$key = $value; + } + return $object; + } + + + /** + * @param $workerId + * @param bool $isWorker + * @throws Exception + */ + public static function clearProcessId($workerId, bool $isWorker = false) + { + clearstatcache(); + $directory = $isWorker === true ? 'pid/worker' : 'pid/task'; + if (!file_exists($file = storage($workerId, $directory))) { + return; + } + shell_exec('rm -rf ' . $file); + } + + + /** + * @param string|null $taskPid + * @throws Exception + */ + public static function clearTaskPid(string $taskPid = null) + { + if (empty($taskPid)) { + exec('rm -rf ' . storage(null, 'pid/task')); + } else { + static::clearProcessId($taskPid); + } + } + + + /** + * @param $taskPid + * @throws Exception + */ + public static function clearWorkerPid($taskPid = null) + { + if (empty($taskPid)) { + exec('rm -rf ' . storage(null, 'pid/worker')); + } else { + static::clearProcessId($taskPid, true); + } + } + + + /** + * @return Server|null + * @throws + */ + public static function getWebSocket(): ?\Swoole\Server + { + $server = static::app()->getSwoole(); + if (!($server instanceof \Swoole\Server)) { + return null; + } + return $server; + } + + + /** + * @return false|string + * @throws Exception + */ + public static function getMasterPid(): bool|string + { + $pid = Kiri::app()->getSwoole()->setting['pid_file']; + + return file_get_contents($pid); + } + + + /** + * @param int $fd + * @param $data + * @return mixed + * @throws Exception + */ + public static function push(int $fd, $data): mixed + { + $server = static::getWebSocket(); + if (empty($server) || !$server->isEstablished($fd)) { + return false; + } + if (!is_string($data)) { + $data = Json::encode($data); + } + return $server->push($fd, $data); + } + + + /** + * @return mixed + */ + public static function localhost(): mixed + { + return current(swoole_get_local_ip()); + } + + + /** + * @param string $class + * @param array $params + * @throws ReflectionException + * @throws Exception + */ + public static function async(string $class, array $params = []) + { + $manager = di(AsyncTaskExecute::class); + $manager->execute(new $class(...$params)); + } + + + /** + * @param array $v1 + * @param array $v2 + * @return float + */ + #[Pure] public static function distance(array $v1, array $v2): float + { + $maxX = max($v1['x'], $v2['x']); + $minX = min($v1['x'], $v2['x']); + + $maxZ = max($v1['z'], $v2['z']); + $minZ = min($v1['z'], $v2['z']); + + $dx = abs($maxX - $minX); + $dy = abs($maxZ - $minZ); + + $sqrt = sqrt($dx * $dx + $dy * $dy); + if ($sqrt < 0) { + $sqrt = abs($sqrt); + } + return (float)$sqrt; + } + + + /** + * @param $process + * @throws Exception + */ + public static function shutdown($process): void + { + static::app()->getSwoole()->shutdown(); + if ($process instanceof Process) { + $process->exit(0); + } + } + + + /** + * @param $tmp_name + * @return string + */ + public static function rename($tmp_name): string + { + $hash = md5_file($tmp_name); + + $later = '.' . exif_imagetype($tmp_name); + + $match = '/(\w{12})(\w{5})(\w{9})(\w{6})/'; + $tmp = preg_replace($match, '$1-$2-$3-$4', $hash); + + return strtoupper($tmp) . $later; + } + + + /** + * @return Environmental + * @throws + */ + public static function getPlatform(): Environmental + { + return Kiri::createObject(Environmental::class); + } + + + /** + * @return mixed + * @throws Exception + */ + public static function reload(): mixed + { + return Kiri::app()->getSwoole()->reload(); + } + + + private static array $_autoload = []; + + + const PROCESS = 'process'; + const TASK = 'task'; + const WORKER = 'worker'; + + + /** + * @param string $event + * @param null $data + * @return false|string + * @throws Exception + */ + public static function param(string $event, $data = NULL): bool|string + { + if (is_object($data)) { + if ($data instanceof ModelInterface || $data instanceof Collection) { + $data = $data->getAttributes(); + } else { + $data = get_object_vars($data); + } + } + if (!is_array($data)) $data = ['data' => $data]; + return json_encode(array_merge(['callback' => $event], $data)); + } + + + /** + * @return string|null + */ + #[Pure] public static function getEnvironmental(): ?string + { + return env('environmental'); + } + + + /** + * @return bool + */ + #[Pure] public static function isTask(): bool + { + return static::getEnvironmental() == static::TASK; + } + + + /** + * @return bool + */ + #[Pure] public static function isWorker(): bool + { + return static::getEnvironmental() == static::WORKER; + } + + + /** + * @return bool + */ + #[Pure] public static function isProcess(): bool + { + return static::getEnvironmental() == static::PROCESS; + } + + + /** + * @param $class + * @param $file + */ + public static function setAutoload($class, $file) + { + if (isset(static::$_autoload[$class])) { + return; + } + static::$_autoload[$class] = $file; + include_once "Kiri.php"; + } + + + /** + * @param $className + */ + public static function autoload($className) + { + if (!isset(static::$_autoload[$className])) { + return; + } + $file = static::$_autoload[$className]; + require_once "Kiri.php"; + } + + +} + +//spl_autoload_register([Kiri::class, 'autoload'], true, true); +Kiri::setContainer(new Container()); diff --git a/composer.json b/composer.json index ee58684d..e2705b4a 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "Kiri\\Task\\": "kiri-task/" }, "files": [ + "Kiri.php", "error.php", "function.php" ] diff --git a/function.php b/function.php index aaf621d4..52a62891 100644 --- a/function.php +++ b/function.php @@ -14,7 +14,6 @@ use Kiri\Error\Logger; use Kiri\Events\EventDispatch; use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; -use Kiri\Kiri; use Kiri\Message\Handler\Router; use Psr\Log\LoggerInterface; use Swoole\Process; diff --git a/kiri-annotation/Event.php b/kiri-annotation/Event.php index 556b1af3..3b5d8356 100644 --- a/kiri-annotation/Event.php +++ b/kiri-annotation/Event.php @@ -6,7 +6,7 @@ namespace Kiri\Annotation; use Exception; use Kiri\Events\EventProvider; -use Kiri\Kiri; +use Kiri; /** diff --git a/kiri-annotation/Inject.php b/kiri-annotation/Inject.php index 124b01a0..53501560 100644 --- a/kiri-annotation/Inject.php +++ b/kiri-annotation/Inject.php @@ -6,7 +6,7 @@ namespace Kiri\Annotation; use Exception; use Kiri\Core\Str; -use Kiri\Kiri; +use Kiri; use ReflectionException; use ReflectionProperty; diff --git a/kiri-annotation/Loader.php b/kiri-annotation/Loader.php index 49d0a46e..15da0f38 100644 --- a/kiri-annotation/Loader.php +++ b/kiri-annotation/Loader.php @@ -7,7 +7,7 @@ namespace Kiri\Annotation; use DirectoryIterator; use Exception; use Kiri\Abstracts\Component; -use Kiri\Kiri; +use Kiri; use ReflectionClass; use ReflectionException; use Throwable; diff --git a/kiri-annotation/Mapping.php b/kiri-annotation/Mapping.php index 81ad1694..37cdf1a6 100644 --- a/kiri-annotation/Mapping.php +++ b/kiri-annotation/Mapping.php @@ -2,7 +2,7 @@ namespace Kiri\Annotation; -use Kiri\Kiri; +use Kiri; #[\Attribute(\Attribute::TARGET_CLASS)] class Mapping extends Attribute { diff --git a/kiri-annotation/Route/Route.php b/kiri-annotation/Route/Route.php index afb1fc2c..ff42d238 100644 --- a/kiri-annotation/Route/Route.php +++ b/kiri-annotation/Route/Route.php @@ -6,7 +6,7 @@ namespace Kiri\Annotation\Route; use Kiri\Annotation\Attribute; use Kiri\Message\Handler\Router; -use Kiri\Kiri; +use Kiri; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Route extends Attribute { diff --git a/kiri-annotation/Task.php b/kiri-annotation/Task.php index b70a8478..27546904 100644 --- a/kiri-annotation/Task.php +++ b/kiri-annotation/Task.php @@ -5,7 +5,7 @@ namespace Kiri\Annotation; use Exception; -use Kiri\Kiri; +use Kiri; use Kiri\Server\Tasker\AsyncTaskExecute; diff --git a/kiri-engine/Abstracts/BaseApplication.php b/kiri-engine/Abstracts/BaseApplication.php index f5205e3e..ad6ae324 100644 --- a/kiri-engine/Abstracts/BaseApplication.php +++ b/kiri-engine/Abstracts/BaseApplication.php @@ -26,7 +26,7 @@ use Swoole\Table; /** * Class BaseApplication - * @package Kiri\Kiri\Base + * @package Kiri\Base */ abstract class BaseApplication extends Component { diff --git a/kiri-engine/Abstracts/Component.php b/kiri-engine/Abstracts/Component.php index 65bf13db..5db7a6ad 100644 --- a/kiri-engine/Abstracts/Component.php +++ b/kiri-engine/Abstracts/Component.php @@ -15,14 +15,14 @@ use JetBrains\PhpStorm\Pure; use Kiri\Di\Container; use Kiri\Events\EventDispatch; use Kiri\Events\EventProvider; -use Kiri\Kiri; +use Kiri; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; /** * Class Component - * @package Kiri\Kiri\Base + * @package Kiri\Base * @property ContainerInterface|Container $container * @property EventProvider $eventProvider * @property EventDispatch $eventDispatch diff --git a/kiri-engine/Abstracts/Config.php b/kiri-engine/Abstracts/Config.php index a2d50f45..6904a0b1 100644 --- a/kiri-engine/Abstracts/Config.php +++ b/kiri-engine/Abstracts/Config.php @@ -14,7 +14,7 @@ use Kiri\Exception\ConfigException; /** * Class Config - * @package Kiri\Kiri\Base + * @package Kiri\Base */ class Config extends Component { diff --git a/kiri-engine/Abstracts/Configure.php b/kiri-engine/Abstracts/Configure.php index d7f9997a..8acf6821 100644 --- a/kiri-engine/Abstracts/Configure.php +++ b/kiri-engine/Abstracts/Configure.php @@ -10,7 +10,7 @@ namespace Kiri\Abstracts; /** * Interface Configure - * @package Kiri\Kiri\Base + * @package Kiri\Base */ interface Configure { diff --git a/kiri-engine/Abstracts/Logger.php b/kiri-engine/Abstracts/Logger.php index 525b744d..825faf1d 100644 --- a/kiri-engine/Abstracts/Logger.php +++ b/kiri-engine/Abstracts/Logger.php @@ -6,7 +6,7 @@ use DirectoryIterator; use Exception; use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; -use Kiri\Kiri; +use Kiri; use Kiri\Server\Events\OnWorkerStop; use Psr\Log\LoggerInterface; use ReflectionException; diff --git a/kiri-engine/Application.php b/kiri-engine/Application.php index dfe4b71b..770eec3d 100644 --- a/kiri-engine/Application.php +++ b/kiri-engine/Application.php @@ -29,6 +29,8 @@ use Symfony\Component\Console\{Application as ConsoleApplication, Output\ConsoleOutput, Output\OutputInterface }; +use Kiri; + /** * Class Init diff --git a/kiri-engine/Async.php b/kiri-engine/Async.php index 2257fe1d..a67cc46e 100644 --- a/kiri-engine/Async.php +++ b/kiri-engine/Async.php @@ -8,7 +8,7 @@ use Exception; use Kiri\Abstracts\Component; use Kiri\Server\ServerManager; use Kiri\Server\Tasker\AsyncTaskExecute; - +use Kiri; /** * Class Async * @package Kiri diff --git a/kiri-engine/Cache/Base/Redis.php b/kiri-engine/Cache/Base/Redis.php index 577c7659..ce547ee6 100644 --- a/kiri-engine/Cache/Base/Redis.php +++ b/kiri-engine/Cache/Base/Redis.php @@ -5,7 +5,7 @@ namespace Kiri\Cache\Base; use Exception; use Kiri\Abstracts\Logger; use Kiri\Exception\RedisConnectException; -use Kiri\Kiri; +use Kiri; use Kiri\Pool\StopHeartbeatCheck; use RedisException; use Swoole\Timer; diff --git a/kiri-engine/Cache/File.php b/kiri-engine/Cache/File.php index 2f676f8d..0fecb18f 100644 --- a/kiri-engine/Cache/File.php +++ b/kiri-engine/Cache/File.php @@ -16,7 +16,7 @@ use Swoole\Coroutine\System; /** * Class File - * @package Kiri\Kiri\Cache + * @package Kiri\Cache */ class File extends Component implements ICache { diff --git a/kiri-engine/Cache/ICache.php b/kiri-engine/Cache/ICache.php index a9ed1efa..496d7c6f 100644 --- a/kiri-engine/Cache/ICache.php +++ b/kiri-engine/Cache/ICache.php @@ -11,7 +11,7 @@ namespace Kiri\Cache; /** * Interface ICache - * @package Kiri\Kiri\Cache + * @package Kiri\Cache */ interface ICache { diff --git a/kiri-engine/Cache/Redis.php b/kiri-engine/Cache/Redis.php index 601c90ee..485e16c7 100644 --- a/kiri-engine/Cache/Redis.php +++ b/kiri-engine/Cache/Redis.php @@ -15,7 +15,7 @@ use Kiri\Abstracts\Config; use Kiri\Core\Json; use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; -use Kiri\Kiri; +use Kiri; use Kiri\Pool\Redis as PoolRedis; use Kiri\Annotation\Inject; use Kiri\Server\Events\OnWorkerExit; @@ -23,7 +23,7 @@ use Swoole\Timer; /** * Class Redis - * @package Kiri\Kiri\Cache + * @package Kiri\Cache * @mixin \Redis */ class Redis extends Component diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index 4596f570..84a80f35 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -5,7 +5,7 @@ namespace Kiri; use Kiri\Abstracts\BaseContext; use Swoole\Coroutine; - +use Kiri; /** * Class Context * @package Yoc\http diff --git a/kiri-engine/Core/DateFormat.php b/kiri-engine/Core/DateFormat.php index f304ed4f..923f8af0 100644 --- a/kiri-engine/Core/DateFormat.php +++ b/kiri-engine/Core/DateFormat.php @@ -13,7 +13,7 @@ namespace Kiri\Core; /** * Class DateFormat - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class DateFormat { diff --git a/kiri-engine/Core/Help.php b/kiri-engine/Core/Help.php index 36e85009..7d4696c9 100644 --- a/kiri-engine/Core/Help.php +++ b/kiri-engine/Core/Help.php @@ -10,7 +10,7 @@ use Exception; /** * Class Help - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class Help { diff --git a/kiri-engine/Core/Json.php b/kiri-engine/Core/Json.php index 04767cf4..2759a7df 100644 --- a/kiri-engine/Core/Json.php +++ b/kiri-engine/Core/Json.php @@ -16,7 +16,7 @@ use Throwable; /** * Class JSON - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class Json { diff --git a/kiri-engine/Core/Reader.php b/kiri-engine/Core/Reader.php index feb89309..a9c97ccb 100644 --- a/kiri-engine/Core/Reader.php +++ b/kiri-engine/Core/Reader.php @@ -6,7 +6,7 @@ namespace Kiri\Core; /** * Class Reader - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class Reader { diff --git a/kiri-engine/Core/Str.php b/kiri-engine/Core/Str.php index 6103f190..b9dbb5f6 100644 --- a/kiri-engine/Core/Str.php +++ b/kiri-engine/Core/Str.php @@ -9,7 +9,7 @@ use Exception; /** * Class Str - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class Str { diff --git a/kiri-engine/Core/Xml.php b/kiri-engine/Core/Xml.php index ad190111..04d29f83 100644 --- a/kiri-engine/Core/Xml.php +++ b/kiri-engine/Core/Xml.php @@ -13,7 +13,7 @@ use Exception; /** * Class Xml - * @package Kiri\Kiri\Core + * @package Kiri\Core */ class Xml { diff --git a/kiri-engine/Di/Container.php b/kiri-engine/Di/Container.php index e7c5e4f7..165118a3 100644 --- a/kiri-engine/Di/Container.php +++ b/kiri-engine/Di/Container.php @@ -9,18 +9,19 @@ declare(strict_types=1); namespace Kiri\Di; -use Kiri\Annotation\Inject; use Closure; use Exception; +use Kiri; use Kiri\Abstracts\Logger; -use Kiri\Kiri; +use Kiri\Annotation\Inject; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use ReflectionClass; use ReflectionException; use ReflectionFunction; use ReflectionMethod; use ReflectionProperty; -use Psr\Container\ContainerInterface; +use static; /** * Class Container @@ -61,36 +62,40 @@ class Container implements ContainerInterface ]; - /** - * @param string $id - * @return mixed - * @throws - */ + /** + * @param string $id + * @return mixed + * @throws + */ public function get(string $id): mixed { + if ($id == ContainerInterface::class) { + return $this; + } return $this->make($id, [], []); } - - /** - * @param $class - * @param array $constrict - * @param array $config - * @return mixed - * @throws - */ - public function make($class, array $constrict = [], array $config = []): mixed - { - if ($this->isInterface($class)) { - $class = $this->_interfaces[$class]; - } - if (!isset($this->_singletons[$class])) { - $this->_singletons[$class] = $this->resolve($class, $constrict, $config); - } - return $this->_singletons[$class]; - } - + /** + * @param $class + * @param array $constrict + * @param array $config + * @return mixed + * @throws + */ + public function make($class, array $constrict = [], array $config = []): mixed + { + if ($class == ContainerInterface::class) { + return $this; + } + if ($this->isInterface($class)) { + $class = $this->_interfaces[$class]; + } + if (!isset($this->_singletons[$class])) { + $this->_singletons[$class] = $this->resolve($class, $constrict, $config); + } + return $this->_singletons[$class]; + } /** @@ -439,12 +444,12 @@ class Container implements ContainerInterface return $old; } - /** - * @param string $id - * @return bool - */ - public function has(string $id): bool - { - return isset($this->_singletons[$id]) || isset($this->_interfaces[$id]); - } + /** + * @param string $id + * @return bool + */ + public function has(string $id): bool + { + return isset($this->_singletons[$id]) || isset($this->_interfaces[$id]); + } } diff --git a/kiri-engine/Di/LocalService.php b/kiri-engine/Di/LocalService.php index a7ef3060..5f3bfbde 100644 --- a/kiri-engine/Di/LocalService.php +++ b/kiri-engine/Di/LocalService.php @@ -3,7 +3,7 @@ namespace Kiri\Di; use Kiri\Abstracts\Component; -use Kiri\Kiri; +use Kiri; /** diff --git a/kiri-engine/Environmental.php b/kiri-engine/Environmental.php index e19d15b2..f05c826d 100644 --- a/kiri-engine/Environmental.php +++ b/kiri-engine/Environmental.php @@ -5,7 +5,7 @@ namespace Kiri; use JetBrains\PhpStorm\Pure; - +use Kiri; /** * Class Environmental diff --git a/kiri-engine/Error/ErrorHandler.php b/kiri-engine/Error/ErrorHandler.php index f4c15853..6a4d7537 100644 --- a/kiri-engine/Error/ErrorHandler.php +++ b/kiri-engine/Error/ErrorHandler.php @@ -14,13 +14,13 @@ use Kiri\Message\Handler\Formatter\IFormatter; use Kiri\Abstracts\Component; use Kiri\Core\Json; use Kiri\Events\EventDispatch; -use Kiri\Kiri; +use Kiri; use Kiri\Message\Events\OnAfterRequest; /** * Class ErrorHandler * - * @package Kiri\Kiri\Base + * @package Kiri\Base * @property-read $asError */ class ErrorHandler extends Component implements ErrorInterface diff --git a/kiri-engine/Error/ErrorInterface.php b/kiri-engine/Error/ErrorInterface.php index e9c78100..5e602169 100644 --- a/kiri-engine/Error/ErrorInterface.php +++ b/kiri-engine/Error/ErrorInterface.php @@ -11,7 +11,7 @@ namespace Kiri\Error; /** * Interface ErrorInterface - * @package Kiri\Kiri\Error + * @package Kiri\Error */ interface ErrorInterface { diff --git a/kiri-engine/Error/Logger.php b/kiri-engine/Error/Logger.php index 84869e2a..23996093 100644 --- a/kiri-engine/Error/Logger.php +++ b/kiri-engine/Error/Logger.php @@ -12,14 +12,14 @@ namespace Kiri\Error; use Exception; use Kiri\Abstracts\Component; use Kiri\Core\Json; -use Kiri\Kiri; +use Kiri; use Kiri\Annotation\Inject; use Psr\Log\LoggerInterface; use Throwable; /** * Class Logger - * @package Kiri\Kiri\Error + * @package Kiri\Error * @mixin \Kiri\Abstracts\Logger */ class Logger extends Component diff --git a/kiri-engine/Error/LoggerAspect.php b/kiri-engine/Error/LoggerAspect.php index 77aecec6..6a9ddcd3 100644 --- a/kiri-engine/Error/LoggerAspect.php +++ b/kiri-engine/Error/LoggerAspect.php @@ -8,7 +8,7 @@ use Exception; use Kiri\Message\Aspect\OnAspectInterface; use Kiri\Message\Aspect\OnJoinPointInterface; use Kiri\Message\Constrict\RequestInterface; -use Kiri\Kiri; +use Kiri; use Psr\Log\LoggerInterface; diff --git a/kiri-engine/Error/LoggerProcess.php b/kiri-engine/Error/LoggerProcess.php index df25876b..ade6455d 100644 --- a/kiri-engine/Error/LoggerProcess.php +++ b/kiri-engine/Error/LoggerProcess.php @@ -7,7 +7,7 @@ namespace Kiri\Error; use Exception; use Kiri\Core\Json; use Kiri\Exception\ComponentException; -use Kiri\Kiri; +use Kiri; use Kiri\Server\Abstracts\BaseProcess; use Kiri\Server\Broadcast\OnBroadcastInterface; use Psr\Log\LoggerInterface; diff --git a/kiri-engine/Event.php b/kiri-engine/Event.php index cd135615..dadd72ec 100644 --- a/kiri-engine/Event.php +++ b/kiri-engine/Event.php @@ -7,7 +7,7 @@ namespace Kiri; use Exception; use Kiri\Abstracts\Component; - +use Kiri; /** * Class Event * @package Kiri diff --git a/kiri-engine/Exception/ComponentException.php b/kiri-engine/Exception/ComponentException.php index 5eb18cc4..54d18aed 100644 --- a/kiri-engine/Exception/ComponentException.php +++ b/kiri-engine/Exception/ComponentException.php @@ -15,7 +15,7 @@ use Throwable; /** * Class ComponentException - * @package Kiri\Kiri\Exception + * @package Kiri\Exception */ class ComponentException extends \Exception { diff --git a/kiri-engine/Exception/NotFindClassException.php b/kiri-engine/Exception/NotFindClassException.php index 4f02d300..ea2c0eea 100644 --- a/kiri-engine/Exception/NotFindClassException.php +++ b/kiri-engine/Exception/NotFindClassException.php @@ -16,7 +16,7 @@ use Throwable; /** * Class NotFindClassException - * @package Kiri\Kiri\Exception + * @package Kiri\Exception */ class NotFindClassException extends \Exception { diff --git a/kiri-engine/Exception/NotFindPropertyException.php b/kiri-engine/Exception/NotFindPropertyException.php index 71c945eb..20ef4ac5 100644 --- a/kiri-engine/Exception/NotFindPropertyException.php +++ b/kiri-engine/Exception/NotFindPropertyException.php @@ -15,7 +15,7 @@ use Throwable; /** * Class NotFindClassException - * @package Kiri\Kiri\Exception + * @package Kiri\Exception */ class NotFindPropertyException extends \Exception { diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 45516f2b..77e06bb2 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -7,7 +7,7 @@ use Kiri\Abstracts\Config; use Kiri\Core\Json; use Kiri\Error\Logger; use Kiri\Exception\ConfigException; -use Kiri\Kiri; +use Kiri; use Kiri\Annotation\Inject; use Swoole\Coroutine; use Swoole\Process; diff --git a/kiri-engine/Pool/Connection.php b/kiri-engine/Pool/Connection.php index 019fd90c..6808301f 100644 --- a/kiri-engine/Pool/Connection.php +++ b/kiri-engine/Pool/Connection.php @@ -9,7 +9,7 @@ use Exception; use Kiri\Abstracts\Component; use Kiri\Abstracts\Config; use Kiri\Context; -use Kiri\Kiri; +use Kiri; use Swoole\Error; use Throwable; diff --git a/kiri-engine/Pool/Redis.php b/kiri-engine/Pool/Redis.php index b856545e..eb1aee93 100644 --- a/kiri-engine/Pool/Redis.php +++ b/kiri-engine/Pool/Redis.php @@ -10,11 +10,11 @@ use Exception; use Kiri\Abstracts\Component; use Kiri\Context; use Kiri\Exception\ConfigException; -use Kiri\Kiri; +use Kiri; /** * Class RedisClient - * @package Kiri\Kiri\Pool + * @package Kiri\Pool */ class Redis extends Component { diff --git a/kiri-engine/Runtime.php b/kiri-engine/Runtime.php index f03c3127..f4afd317 100644 --- a/kiri-engine/Runtime.php +++ b/kiri-engine/Runtime.php @@ -10,7 +10,7 @@ use Kiri\Abstracts\Input; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; - +use Kiri; /** * Class Runtime diff --git a/kiri-gii/Gii.php b/kiri-gii/Gii.php index 62c36286..d3cb4f2e 100644 --- a/kiri-gii/Gii.php +++ b/kiri-gii/Gii.php @@ -13,7 +13,7 @@ use Database\Connection; use Database\Db; use Exception; use Kiri\Cache\Redis; -use Kiri\Kiri; +use Kiri; use Symfony\Component\Console\Input\InputInterface; /** diff --git a/kiri-gii/GiiCommand.php b/kiri-gii/GiiCommand.php index 7a219ba1..3a86f40f 100644 --- a/kiri-gii/GiiCommand.php +++ b/kiri-gii/GiiCommand.php @@ -7,7 +7,7 @@ namespace Gii; use Exception; use Kiri\Abstracts\Config; use Kiri\Exception\ConfigException; -use Kiri\Kiri; +use Kiri; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; diff --git a/kiri-gii/GiiController.php b/kiri-gii/GiiController.php index 851a5308..740a250d 100644 --- a/kiri-gii/GiiController.php +++ b/kiri-gii/GiiController.php @@ -6,7 +6,7 @@ namespace Gii; use Exception; use ReflectionException; -use Kiri\Kiri; +use Kiri; /** * Class GiiController diff --git a/kiri-gii/GiiMiddleware.php b/kiri-gii/GiiMiddleware.php index 01ad070b..db2c58c5 100644 --- a/kiri-gii/GiiMiddleware.php +++ b/kiri-gii/GiiMiddleware.php @@ -6,7 +6,7 @@ namespace Gii; use Exception; -use Kiri\Kiri; +use Kiri; /** * Class GiiMiddleware diff --git a/kiri-gii/GiiModel.php b/kiri-gii/GiiModel.php index dae9cfbd..fd420d97 100644 --- a/kiri-gii/GiiModel.php +++ b/kiri-gii/GiiModel.php @@ -8,7 +8,7 @@ use Database\Db; use Database\Model; use Exception; use ReflectionException; -use Kiri\Kiri; +use Kiri; /** * Class GiiModel diff --git a/kiri-gii/GiiProviders.php b/kiri-gii/GiiProviders.php index 1a0489d8..571c008f 100644 --- a/kiri-gii/GiiProviders.php +++ b/kiri-gii/GiiProviders.php @@ -8,7 +8,7 @@ namespace Gii; use Exception; use Kiri\Abstracts\Providers; use Kiri\Application; -use Kiri\Kiri; +use Kiri; /** * Class DatabasesProviders diff --git a/kiri-gii/GiiRpcClient.php b/kiri-gii/GiiRpcClient.php index 6c53b17c..bc81a532 100644 --- a/kiri-gii/GiiRpcClient.php +++ b/kiri-gii/GiiRpcClient.php @@ -5,7 +5,7 @@ namespace Gii; use Exception; -use Kiri\Kiri; +use Kiri; /** * Class GiiRpcClient @@ -42,7 +42,7 @@ use Kiri\Annotation\Target; use Exception; use Rpc\Client; use Kiri\Core\Json; -use Kiri\Kiri; +use Kiri; '; diff --git a/kiri-gii/GiiRpcService.php b/kiri-gii/GiiRpcService.php index 6a26d0dd..cca5f488 100644 --- a/kiri-gii/GiiRpcService.php +++ b/kiri-gii/GiiRpcService.php @@ -5,7 +5,7 @@ namespace Gii; use Exception; -use Kiri\Kiri; +use Kiri; /** * Class GiiRpcClient diff --git a/kiri-gii/GiiTask.php b/kiri-gii/GiiTask.php index 1b87b49d..5a2b6479 100644 --- a/kiri-gii/GiiTask.php +++ b/kiri-gii/GiiTask.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Gii; use Exception; -use Kiri\Kiri; +use Kiri; /** * Class GiiModel diff --git a/kiri-websocket-server/Sender.php b/kiri-websocket-server/Sender.php index 9cdbb070..c8c768a7 100644 --- a/kiri-websocket-server/Sender.php +++ b/kiri-websocket-server/Sender.php @@ -2,7 +2,7 @@ namespace Kiri\Websocket; -use Kiri\Kiri; +use Kiri; use Swoole\{Coroutine\Http\Server as AliasServer, WebSocket\Server};