eee
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.4",
|
"php": ">=8.5",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-fileinfo": "*",
|
"ext-fileinfo": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
|
|||||||
@@ -46,13 +46,21 @@ abstract class BaseApplication extends LocalService
|
|||||||
public function __construct(public EventProvider $provider, public ConfigProvider $config, public ContainerInterface $container)
|
public function __construct(public EventProvider $provider, public ConfigProvider $config, public ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->mapping($config);
|
$this->mapping($config);
|
||||||
$this->parseStorage($config);
|
|
||||||
$this->parseEvents($config);
|
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @throws
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->parseStorage($this->config);
|
||||||
|
$this->parseEvents($this->config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConfigProvider $config
|
* @param ConfigProvider $config
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: whwyy
|
|
||||||
* Date: 2018/3/30 0030
|
|
||||||
* Time: 14:28
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Kiri\Abstracts;
|
namespace Kiri\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
@@ -18,112 +11,55 @@ use Kiri\Events\EventDispatch;
|
|||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
/**
|
class Component
|
||||||
* Class Component
|
|
||||||
* @package Kiri\Base
|
|
||||||
* @property ContainerInterface $container
|
|
||||||
* @property EventDispatch $dispatch
|
|
||||||
* @property EventProvider $provider
|
|
||||||
*/
|
|
||||||
class Component implements Configure
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function init(): void
|
||||||
* BaseAbstract constructor.
|
{
|
||||||
*/
|
}
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[Pure] public static function className(): string
|
||||||
|
{
|
||||||
|
return static::class;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function init(): void
|
public function getLogger(): StdoutLogger
|
||||||
{
|
{
|
||||||
}
|
return Kiri::getLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDispatch(): EventDispatch
|
||||||
|
{
|
||||||
|
return Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function getProvider(): EventProvider
|
||||||
* @return string
|
{
|
||||||
*/
|
return Kiri::getDi()->get(EventProvider::class);
|
||||||
#[Pure] public static function className(): string
|
}
|
||||||
{
|
|
||||||
return static::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public function getContainer(): ContainerInterface
|
||||||
|
{
|
||||||
|
return Kiri::getDi();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return StdoutLogger
|
* @throws
|
||||||
* @throws
|
*/
|
||||||
*/
|
public function __get(string $name)
|
||||||
public function getLogger(): StdoutLogger
|
{
|
||||||
{
|
$method = 'get' . ucfirst($name);
|
||||||
return Kiri::getLogger();
|
if (method_exists($this, $method)) {
|
||||||
}
|
return $this->{$method}();
|
||||||
|
}
|
||||||
|
throw new Exception('Unable getting property ' . get_called_class() . '::' . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @return mixed
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public function __get(string $name)
|
|
||||||
{
|
|
||||||
$method = 'get' . ucfirst($name);
|
|
||||||
if (method_exists($this, $method)) {
|
|
||||||
return $this->{$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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: whwyy
|
|
||||||
* Date: 2018/3/30 0030
|
|
||||||
* Time: 14:11
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
namespace Kiri\Abstracts;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface Configure
|
|
||||||
* @package Kiri\Base
|
|
||||||
*/
|
|
||||||
interface Configure
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,9 +7,7 @@ use Kiri\Coordinator;
|
|||||||
class CoordinatorManager
|
class CoordinatorManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static array $_items = [];
|
||||||
|
|
||||||
private static array $_waite = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,10 +16,10 @@ class CoordinatorManager
|
|||||||
*/
|
*/
|
||||||
public static function utility(string $category): Coordinator
|
public static function utility(string $category): Coordinator
|
||||||
{
|
{
|
||||||
if (!((static::$_waite[$category] ?? null) instanceof Coordinator)) {
|
if (!((static::$_items[$category] ?? null) instanceof Coordinator)) {
|
||||||
static::$_waite[$category] = new Coordinator();
|
static::$_items[$category] = new Coordinator();
|
||||||
}
|
}
|
||||||
return static::$_waite[$category];
|
return static::$_items[$category];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,9 +57,12 @@ class Application extends BaseApplication
|
|||||||
$this->errorHandler->registerShutdownHandler(config('site.error.shutdown', []));
|
$this->errorHandler->registerShutdownHandler(config('site.error.shutdown', []));
|
||||||
$this->errorHandler->registerExceptionHandler(config('site.error.exception', []));
|
$this->errorHandler->registerExceptionHandler(config('site.error.exception', []));
|
||||||
$this->errorHandler->registerErrorHandler(config('site.error.error', []));
|
$this->errorHandler->registerErrorHandler(config('site.error.error', []));
|
||||||
|
|
||||||
$this->id = config('site.id', uniqid('id.'));
|
$this->id = config('site.id', uniqid('id.'));
|
||||||
|
|
||||||
$this->provider->on(OnBeforeCommandExecute::class, [$this, 'beforeCommandExecute']);
|
$this->provider->on(OnBeforeCommandExecute::class, [$this, 'beforeCommandExecute']);
|
||||||
|
|
||||||
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
namespace Kiri;
|
namespace Kiri;
|
||||||
|
|
||||||
|
use Swoole\Coroutine;
|
||||||
|
use Swoole\Coroutine\Channel;
|
||||||
|
|
||||||
class Coordinator
|
class Coordinator
|
||||||
{
|
{
|
||||||
|
|
||||||
const string WORKER_START = 'worker:start';
|
const string WORKER_START = 'worker:start';
|
||||||
|
|
||||||
private bool $waite = true;
|
private bool $wait = true;
|
||||||
|
|
||||||
|
private ?Channel $channel = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,18 +21,24 @@ class Coordinator
|
|||||||
*/
|
*/
|
||||||
public function yield(): void
|
public function yield(): void
|
||||||
{
|
{
|
||||||
while ($this->waite) {
|
if (Coroutine::getCid() > 0) {
|
||||||
usleep(1000);
|
$this->channel = new Channel(1);
|
||||||
}
|
$this->channel->pop();
|
||||||
|
} else {
|
||||||
|
while ($this->wait) {
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @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
|
public function done(): void
|
||||||
{
|
{
|
||||||
$this->waite = false;
|
$this->wait = false;
|
||||||
|
$this->channel?->push(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,9 @@ class Environmental
|
|||||||
*/
|
*/
|
||||||
public function isMac(): bool
|
public function isMac(): bool
|
||||||
{
|
{
|
||||||
$output = strtolower(PHP_OS | PHP_OS_FAMILY);
|
$os = strtolower(PHP_OS);
|
||||||
if (str_contains('mac', $output)) {
|
|
||||||
return true;
|
return str_contains($os, 'mac') || str_contains($os, 'darwin');
|
||||||
} else if (str_contains('darwin', $output)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,11 +33,7 @@ class Environmental
|
|||||||
*/
|
*/
|
||||||
#[Pure] public function isLinux(): bool
|
#[Pure] public function isLinux(): bool
|
||||||
{
|
{
|
||||||
if (!static::isMac()) {
|
return PHP_OS_FAMILY === 'Linux' || strtolower(PHP_OS) === 'linux';
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user