eee
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,129 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/3/30 0030
|
||||
* Time: 14:28
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri;
|
||||
use Kiri\Error\StdoutLogger;
|
||||
use Kiri\Events\EventDispatch;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class Component
|
||||
* @package Kiri\Base
|
||||
* @property ContainerInterface $container
|
||||
* @property EventDispatch $dispatch
|
||||
* @property EventProvider $provider
|
||||
*/
|
||||
class Component implements Configure
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* BaseAbstract constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] public static function className(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return StdoutLogger
|
||||
* @throws
|
||||
*/
|
||||
public function getLogger(): StdoutLogger
|
||||
{
|
||||
return Kiri::getLogger();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri;
|
||||
use Kiri\Error\StdoutLogger;
|
||||
use Kiri\Events\EventDispatch;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Component
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
#[Pure] public static function className(): string
|
||||
{
|
||||
return static::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws
|
||||
*/
|
||||
public function getLogger(): StdoutLogger
|
||||
{
|
||||
return Kiri::getLogger();
|
||||
}
|
||||
|
||||
public function getDispatch(): EventDispatch
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
|
||||
|
||||
private static array $_waite = [];
|
||||
private static array $_items = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,10 +16,10 @@ class CoordinatorManager
|
||||
*/
|
||||
public static function utility(string $category): Coordinator
|
||||
{
|
||||
if (!((static::$_waite[$category] ?? null) instanceof Coordinator)) {
|
||||
static::$_waite[$category] = new Coordinator();
|
||||
if (!((static::$_items[$category] ?? null) instanceof Coordinator)) {
|
||||
static::$_items[$category] = new Coordinator();
|
||||
}
|
||||
return static::$_waite[$category];
|
||||
return static::$_items[$category];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
interface Kernel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCommands(): array;
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
interface Kernel
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCommands(): array;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
interface Provider
|
||||
{
|
||||
|
||||
public function onImport();
|
||||
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
interface Provider
|
||||
{
|
||||
|
||||
public function onImport();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
/**
|
||||
* Class Providers
|
||||
* @package Kiri\Abstracts
|
||||
*/
|
||||
abstract class Providers extends Component implements Provider
|
||||
{
|
||||
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Abstracts;
|
||||
|
||||
|
||||
/**
|
||||
* Class Providers
|
||||
* @package Kiri\Abstracts
|
||||
*/
|
||||
abstract class Providers extends Component implements Provider
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -57,9 +57,12 @@ class Application extends BaseApplication
|
||||
$this->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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Kiri;
|
||||
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine\Channel;
|
||||
|
||||
class Coordinator
|
||||
{
|
||||
|
||||
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
|
||||
{
|
||||
while ($this->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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user