From 8479106b9f26af8be1a2c8af9a04c8bbfce67be2 Mon Sep 17 00:00:00 2001 From: whwyy Date: Fri, 12 Jun 2026 23:57:25 +0800 Subject: [PATCH] eee --- Kiri.php | 66 ------- composer.json | 2 +- kiri-engine/Abstracts/BaseApplication.php | 14 +- kiri-engine/Abstracts/Component.php | 194 +++++++------------ kiri-engine/Abstracts/Configure.php | 18 -- kiri-engine/Abstracts/CoordinatorManager.php | 10 +- kiri-engine/Abstracts/Kernel.php | 30 +-- kiri-engine/Abstracts/Provider.php | 24 +-- kiri-engine/Abstracts/Providers.php | 28 +-- kiri-engine/Application.php | 3 + kiri-engine/Coordinator.php | 28 ++- kiri-engine/Environmental.php | 17 +- 12 files changed, 148 insertions(+), 286 deletions(-) delete mode 100644 kiri-engine/Abstracts/Configure.php diff --git a/Kiri.php b/Kiri.php index 94f83689..37157267 100644 --- a/Kiri.php +++ b/Kiri.php @@ -37,13 +37,6 @@ class Kiri } - /** - * @return Container|null - */ - public static function getContainerContext(): ?Container - { - return static::getContainer(); - } /** @@ -131,17 +124,6 @@ class Kiri } - /** - * @return bool - */ - public static function isDocker(): bool - { - $output = shell_exec('[ -f /.dockerenv ] && echo yes || echo no'); - if (trim($output) === 'yes') { - return true; - } - return false; - } /** @@ -177,54 +159,6 @@ class Kiri } - /** - * @return mixed - */ - public static function localhost(): mixed - { - return current(swoole_get_local_ip()); - } - - - /** - * @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 $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; - } /** diff --git a/composer.json b/composer.json index 7b1ce63c..5d13a96b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "license": "MIT", "require": { - "php": ">=8.4", + "php": ">=8.5", "ext-json": "*", "ext-fileinfo": "*", "ext-pdo": "*", diff --git a/kiri-engine/Abstracts/BaseApplication.php b/kiri-engine/Abstracts/BaseApplication.php index d9ddaf3b..c6664251 100644 --- a/kiri-engine/Abstracts/BaseApplication.php +++ b/kiri-engine/Abstracts/BaseApplication.php @@ -46,13 +46,21 @@ abstract class BaseApplication extends LocalService public function __construct(public EventProvider $provider, public ConfigProvider $config, public ContainerInterface $container) { $this->mapping($config); - $this->parseStorage($config); - $this->parseEvents($config); - parent::__construct(); } + /** + * @return void + * @throws + */ + public function init(): void + { + $this->parseStorage($this->config); + $this->parseEvents($this->config); + } + + /** * @param ConfigProvider $config * @return void diff --git a/kiri-engine/Abstracts/Component.php b/kiri-engine/Abstracts/Component.php index 3ed525a2..63afddfa 100644 --- a/kiri-engine/Abstracts/Component.php +++ b/kiri-engine/Abstracts/Component.php @@ -1,129 +1,65 @@ -{$method}(); - } else if (method_exists($this, $name)) { - return $this->{$name}; - } else { - throw new Exception('Unable getting property ' . get_called_class() . '::' . $name); - } - } - - - /** - * @param string $name - * @param $value - * @return void - * @throws - */ - public function __set(string $name, $value): void - { - $method = 'set' . ucfirst($name); - if (method_exists($this, $method)) { - $this->{$method}($value); - } else if (method_exists($this, $name)) { - $this->{$name} = $value; - } else { - throw new Exception('Unable setting property ' . get_called_class() . '::' . $name); - } - } - - - /** - * @return EventDispatch - */ - public function getDispatch(): EventDispatch - { - return Kiri::getDi()->get(EventDispatch::class); - } - - - /** - * @return EventProvider - */ - public function getProvider(): EventProvider - { - return Kiri::getDi()->get(EventProvider::class); - } - - - /** - * @return ContainerInterface - */ - public function getContainer(): ContainerInterface - { - return Kiri::getDi(); - } -} +get(EventDispatch::class); + } + + public function getProvider(): EventProvider + { + return Kiri::getDi()->get(EventProvider::class); + } + + public function getContainer(): ContainerInterface + { + return Kiri::getDi(); + } + + /** + * @throws + */ + public function __get(string $name) + { + $method = 'get' . ucfirst($name); + if (method_exists($this, $method)) { + return $this->{$method}(); + } + throw new Exception('Unable getting property ' . get_called_class() . '::' . $name); + } + +} diff --git a/kiri-engine/Abstracts/Configure.php b/kiri-engine/Abstracts/Configure.php deleted file mode 100644 index 8acf6821..00000000 --- a/kiri-engine/Abstracts/Configure.php +++ /dev/null @@ -1,18 +0,0 @@ -errorHandler->registerShutdownHandler(config('site.error.shutdown', [])); $this->errorHandler->registerExceptionHandler(config('site.error.exception', [])); $this->errorHandler->registerErrorHandler(config('site.error.error', [])); + $this->id = config('site.id', uniqid('id.')); $this->provider->on(OnBeforeCommandExecute::class, [$this, 'beforeCommandExecute']); + + parent::init(); } diff --git a/kiri-engine/Coordinator.php b/kiri-engine/Coordinator.php index 91ac2add..c4544b9b 100644 --- a/kiri-engine/Coordinator.php +++ b/kiri-engine/Coordinator.php @@ -1,15 +1,19 @@ waite) { - usleep(1000); - } + if (Coroutine::getCid() > 0) { + $this->channel = new Channel(1); + $this->channel->pop(); + } else { + while ($this->wait) { + usleep(1000); + } + } } /** * @return void */ - public function waite(): void + public function wait(): void { - $this->waite = true; + $this->wait = true; + $this->channel = null; } @@ -37,8 +47,8 @@ class Coordinator */ public function done(): void { - $this->waite = false; + $this->wait = false; + $this->channel?->push(true); } - } diff --git a/kiri-engine/Environmental.php b/kiri-engine/Environmental.php index 9dd46dc7..b1bd5e58 100644 --- a/kiri-engine/Environmental.php +++ b/kiri-engine/Environmental.php @@ -22,14 +22,9 @@ class Environmental */ public function isMac(): bool { - $output = strtolower(PHP_OS | PHP_OS_FAMILY); - if (str_contains('mac', $output)) { - return true; - } else if (str_contains('darwin', $output)) { - return true; - } else { - return false; - } + $os = strtolower(PHP_OS); + + return str_contains($os, 'mac') || str_contains($os, 'darwin'); } @@ -38,11 +33,7 @@ class Environmental */ #[Pure] public function isLinux(): bool { - if (!static::isMac()) { - return true; - } else { - return false; - } + return PHP_OS_FAMILY === 'Linux' || strtolower(PHP_OS) === 'linux'; } }