This commit is contained in:
2020-09-03 11:39:20 +08:00
parent 274332207b
commit efbb049824
42 changed files with 101 additions and 101 deletions
+2 -2
View File
@@ -123,7 +123,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
*/ */
public function getLastError() public function getLastError()
{ {
return Snowflake::get()->getLogger()->getLastError('mysql'); return Snowflake::app()->getLogger()->getLastError('mysql');
} }
/** /**
@@ -768,7 +768,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
*/ */
public static function setDatabaseConnect($bsName) public static function setDatabaseConnect($bsName)
{ {
return Snowflake::get()->db->get($bsName); return Snowflake::app()->db->get($bsName);
} }
/** /**
+14 -14
View File
@@ -67,7 +67,7 @@ class Connection extends Component
*/ */
public function init() public function init()
{ {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->on(Event::RELEASE_ALL, [$this, 'disconnect']); $event->on(Event::RELEASE_ALL, [$this, 'disconnect']);
$event->on(Event::EVENT_AFTER_REQUEST, [$this, 'clear_connection']); $event->on(Event::EVENT_AFTER_REQUEST, [$this, 'clear_connection']);
} }
@@ -83,7 +83,7 @@ class Connection extends Component
} }
$this->beginTransaction(); $this->beginTransaction();
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->on(Connection::TRANSACTION_COMMIT, [$this, 'commit'], false, true); $event->on(Connection::TRANSACTION_COMMIT, [$this, 'commit'], false, true);
$event->on(Connection::TRANSACTION_ROLLBACK, [$this, 'rollback'], false, true); $event->on(Connection::TRANSACTION_ROLLBACK, [$this, 'rollback'], false, true);
} }
@@ -95,7 +95,7 @@ class Connection extends Component
*/ */
public function getConnect($sql = NULL) public function getConnect($sql = NULL)
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->initConnections($this->cds, true, $this->maxNumber); $connections->initConnections($this->cds, true, $this->maxNumber);
$connections->initConnections($this->slaveConfig['cds'], false, $this->maxNumber); $connections->initConnections($this->slaveConfig['cds'], false, $this->maxNumber);
$connections->setTimeout($this->timeout); $connections->setTimeout($this->timeout);
@@ -155,7 +155,7 @@ class Connection extends Component
if (!$this->enableCache) { if (!$this->enableCache) {
return null; return null;
} }
return Snowflake::get()->get($this->cacheDriver); return Snowflake::app()->get($this->cacheDriver);
} }
/** /**
@@ -169,7 +169,7 @@ class Connection extends Component
'username' => $this->username, 'username' => $this->username,
'password' => $this->password 'password' => $this->password
]; ];
$pool = Snowflake::get()->connections; $pool = Snowflake::app()->connections;
return $pool->getConnection($config, true); return $pool->getConnection($config, true);
} }
@@ -183,7 +183,7 @@ class Connection extends Component
return $this->masterInstance(); return $this->masterInstance();
} }
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
return $connections->getConnection($this->slaveConfig, false); return $connections->getConnection($this->slaveConfig, false);
} }
@@ -194,7 +194,7 @@ class Connection extends Component
*/ */
public function beginTransaction() public function beginTransaction()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->beginTransaction($this->cds); $connections->beginTransaction($this->cds);
return $this; return $this;
} }
@@ -205,7 +205,7 @@ class Connection extends Component
*/ */
public function inTransaction() public function inTransaction()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
return $connections->inTransaction($this->cds); return $connections->inTransaction($this->cds);
} }
@@ -215,7 +215,7 @@ class Connection extends Component
*/ */
public function rollback() public function rollback()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
return $connections->rollback($this->cds); return $connections->rollback($this->cds);
} }
@@ -225,7 +225,7 @@ class Connection extends Component
*/ */
public function commit() public function commit()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
return $connections->commit($this->cds); return $connections->commit($this->cds);
} }
@@ -275,7 +275,7 @@ class Connection extends Component
*/ */
public function release() public function release()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->release($this->cds, true); $connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false); $connections->release($this->slaveConfig['cds'], false);
@@ -287,7 +287,7 @@ class Connection extends Component
*/ */
public function recovery() public function recovery()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->release($this->cds, true); $connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false); $connections->release($this->slaveConfig['cds'], false);
@@ -300,7 +300,7 @@ class Connection extends Component
*/ */
public function clear_connection() public function clear_connection()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->release($this->cds, true); $connections->release($this->cds, true);
$connections->release($this->slaveConfig['cds'], false); $connections->release($this->slaveConfig['cds'], false);
@@ -312,7 +312,7 @@ class Connection extends Component
*/ */
public function disconnect() public function disconnect()
{ {
$connections = Snowflake::get()->connections; $connections = Snowflake::app()->connections;
$connections->disconnect($this->cds); $connections->disconnect($this->cds);
$connections->disconnect($this->slaveConfig['cds']); $connections->disconnect($this->slaveConfig['cds']);
} }
+1 -1
View File
@@ -38,7 +38,7 @@ class DatabasesProviders extends Providers
*/ */
public function get($name) public function get($name)
{ {
$application = Snowflake::get(); $application = Snowflake::app();
if ($application->has('databases.' . $name)) { if ($application->has('databases.' . $name)) {
return $application->get('databases.' . $name); return $application->get('databases.' . $name);
} }
+12 -12
View File
@@ -46,7 +46,7 @@ class Db
*/ */
public static function commit() public static function commit()
{ {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Connection::TRANSACTION_COMMIT); $event->trigger(Connection::TRANSACTION_COMMIT);
$event->offName(Connection::TRANSACTION_COMMIT); $event->offName(Connection::TRANSACTION_COMMIT);
static::$isActive = false; static::$isActive = false;
@@ -57,7 +57,7 @@ class Db
*/ */
public static function rollback() public static function rollback()
{ {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Connection::TRANSACTION_ROLLBACK); $event->trigger(Connection::TRANSACTION_ROLLBACK);
$event->offName(Connection::TRANSACTION_ROLLBACK); $event->offName(Connection::TRANSACTION_ROLLBACK);
static::$isActive = false; static::$isActive = false;
@@ -96,7 +96,7 @@ class Db
public function get(Connection $db = NULL) public function get(Connection $db = NULL)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$query = $db->getSchema()->getQueryBuilder(); $query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this)) return $db->createCommand($query->getQuery($this))
@@ -120,7 +120,7 @@ class Db
public function find(Connection $db = NULL) public function find(Connection $db = NULL)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$query = $db->getSchema()->getQueryBuilder(); $query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this)) return $db->createCommand($query->getQuery($this))
@@ -135,7 +135,7 @@ class Db
public function count(Connection $db = NULL) public function count(Connection $db = NULL)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$query = $db->getSchema()->getQueryBuilder(); $query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->count($this)) return $db->createCommand($query->count($this))
@@ -150,7 +150,7 @@ class Db
public function exists(Connection $db = NULL) public function exists(Connection $db = NULL)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$query = $db->getSchema()->getQueryBuilder(); $query = $db->getSchema()->getQueryBuilder();
return $db->createCommand($query->getQuery($this)) return $db->createCommand($query->getQuery($this))
@@ -221,7 +221,7 @@ class Db
public function delete($db = null) public function delete($db = null)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$query = $db->getBuild()->builder($this); $query = $db->getBuild()->builder($this);
@@ -238,7 +238,7 @@ class Db
public static function drop($table, $db = null) public static function drop($table, $db = null)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
return $db->createCommand('DROP TABLE ' . $table)->delete(); return $db->createCommand('DROP TABLE ' . $table)->delete();
} }
@@ -253,7 +253,7 @@ class Db
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
return $db->createCommand('TRUNCATE ' . $table)->exec(); return $db->createCommand('TRUNCATE ' . $table)->exec();
@@ -269,7 +269,7 @@ class Db
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
@@ -289,7 +289,7 @@ class Db
public static function desc($table, Connection $db = NULL) public static function desc($table, Connection $db = NULL)
{ {
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
if (empty($table)) { if (empty($table)) {
@@ -313,7 +313,7 @@ class Db
} }
if (empty($db)) { if (empty($db)) {
$db = Snowflake::get()->database; $db = Snowflake::app()->database;
} }
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';']; $table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
+2 -2
View File
@@ -28,7 +28,7 @@ abstract class Callback extends Application
protected function clear($server, $worker_id, $message) protected function clear($server, $worker_id, $message)
{ {
Timer::clearAll(); Timer::clearAll();
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->offName(Event::EVENT_AFTER_REQUEST); $event->offName(Event::EVENT_AFTER_REQUEST);
$event->offName(Event::EVENT_BEFORE_REQUEST); $event->offName(Event::EVENT_BEFORE_REQUEST);
@@ -36,7 +36,7 @@ abstract class Callback extends Application
Snowflake::clearProcessId($server->worker_pid); Snowflake::clearProcessId($server->worker_pid);
$logger = Snowflake::get()->getLogger(); $logger = Snowflake::app()->getLogger();
$logger->write($this->_MESSAGE[$message] . $worker_id); $logger->write($this->_MESSAGE[$message] . $worker_id);
$logger->clear(); $logger->clear();
} }
+1 -1
View File
@@ -22,7 +22,7 @@ class Application extends HttpService
*/ */
protected function write($message, $category = 'app') protected function write($message, $category = 'app')
{ {
$logger = Snowflake::get()->logger; $logger = Snowflake::app()->logger;
$logger->write($message, $category); $logger->write($message, $category);
$logger->insert(); $logger->insert();
} }
+1 -1
View File
@@ -35,7 +35,7 @@ class Command extends \Console\Command
$action = $dtl->get('action', 3); $action = $dtl->get('action', 3);
/** @var Server $server */ /** @var Server $server */
$server = Snowflake::get()->get('server'); $server = Snowflake::app()->get('server');
$server->start(); $server->start();
} }
+1 -1
View File
@@ -83,7 +83,7 @@ class Controller extends Application
public function getRequest(): Request public function getRequest(): Request
{ {
if (!$this->request) { if (!$this->request) {
$this->request = Snowflake::get()->request; $this->request = Snowflake::app()->request;
} }
return $this->request; return $this->request;
} }
+1 -1
View File
@@ -26,7 +26,7 @@ class OnAfterReload extends Callback
*/ */
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
$event = Snowflake::get()->getEvent(); $event = Snowflake::app()->getEvent();
if (!$event->exists(Event::SERVER_AFTER_RELOAD)) { if (!$event->exists(Event::SERVER_AFTER_RELOAD)) {
return; return;
} }
+1 -1
View File
@@ -23,7 +23,7 @@ class OnBeforeReload extends Callback
*/ */
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
$event = Snowflake::get()->getEvent(); $event = Snowflake::app()->getEvent();
if (!$event->exists(Event::SERVER_BEFORE_RELOAD)) { if (!$event->exists(Event::SERVER_BEFORE_RELOAD)) {
return; return;
} }
+5 -5
View File
@@ -38,10 +38,10 @@ class OnClose extends Callback
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->addError($exception->getMessage()); $this->addError($exception->getMessage());
} finally { } finally {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::RELEASE_ALL); $event->trigger(Event::RELEASE_ALL);
$logger = Snowflake::get()->getLogger(); $logger = Snowflake::app()->getLogger();
$logger->insert(); $logger->insert();
} }
} }
@@ -59,13 +59,13 @@ class OnClose extends Callback
if (!$server->isEstablished($fd)) { if (!$server->isEstablished($fd)) {
return [null, null]; return [null, null];
} }
$manager = Snowflake::get()->annotation->get('websocket'); $manager = Snowflake::app()->annotation->get('websocket');
$name = $manager->getName(AWebsocket::CLOSE); $name = $manager->getName(AWebsocket::CLOSE);
} else if ($server instanceof HServer) { } else if ($server instanceof HServer) {
$manager = Snowflake::get()->annotation->get('http'); $manager = Snowflake::app()->annotation->get('http');
$name = $manager->getName(Annotation::CLOSE); $name = $manager->getName(Annotation::CLOSE);
} else { } else {
$manager = Snowflake::get()->annotation->get('tcp'); $manager = Snowflake::app()->annotation->get('tcp');
$name = $manager->getName(Tcp::CLOSE); $name = $manager->getName(Tcp::CLOSE);
} }
return [$manager, $name]; return [$manager, $name];
+1 -1
View File
@@ -27,7 +27,7 @@ class OnConnect extends Callback
*/ */
public function onHandler(\Swoole\Server $server, int $fd, int $reactorId) public function onHandler(\Swoole\Server $server, int $fd, int $reactorId)
{ {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
if (!$event->exists(Event::RECEIVE_CONNECTION)) { if (!$event->exists(Event::RECEIVE_CONNECTION)) {
return; return;
} }
+1 -1
View File
@@ -53,7 +53,7 @@ class OnHandshake extends Callback
} }
/** @var AWebsocket $manager */ /** @var AWebsocket $manager */
$manager = Snowflake::get()->annotation->get('websocket'); $manager = Snowflake::app()->annotation->get('websocket');
if ($manager->has($manager->getName(AWebsocket::HANDSHAKE))) { if ($manager->has($manager->getName(AWebsocket::HANDSHAKE))) {
$manager->runWith($manager->getName(AWebsocket::HANDSHAKE), [$request, $response]); $manager->runWith($manager->getName(AWebsocket::HANDSHAKE), [$request, $response]);
} else { } else {
+1 -1
View File
@@ -21,7 +21,7 @@ class OnManagerStart extends Callback
$this->debug('manager start.'); $this->debug('manager start.');
Snowflake::setProcessId($server->manager_pid); Snowflake::setProcessId($server->manager_pid);
$events = Snowflake::get()->event; $events = Snowflake::app()->event;
if ($events->exists(Event::SERVER_MANAGER_START)) { if ($events->exists(Event::SERVER_MANAGER_START)) {
$events->trigger(Event::SERVER_MANAGER_START, null, $server); $events->trigger(Event::SERVER_MANAGER_START, null, $server);
} }
+1 -1
View File
@@ -24,7 +24,7 @@ class OnManagerStop extends Callback
{ {
$this->warning('manager stop.'); $this->warning('manager stop.');
$events = Snowflake::get()->event; $events = Snowflake::app()->event;
if ($events->exists(Event::SERVER_MANAGER_STOP)) { if ($events->exists(Event::SERVER_MANAGER_STOP)) {
$events->trigger(Event::SERVER_MANAGER_STOP, [$server]); $events->trigger(Event::SERVER_MANAGER_STOP, [$server]);
} }
+4 -4
View File
@@ -29,7 +29,7 @@ class OnMessage extends Callback
if ($frame->opcode == 0x08) { if ($frame->opcode == 0x08) {
return; return;
} }
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
if ($event->exists(Event::SERVER_MESSAGE)) { if ($event->exists(Event::SERVER_MESSAGE)) {
$event->trigger(Event::SERVER_MESSAGE, [$server, $frame]); $event->trigger(Event::SERVER_MESSAGE, [$server, $frame]);
} else { } else {
@@ -37,7 +37,7 @@ class OnMessage extends Callback
} }
/** @var AWebsocket $manager */ /** @var AWebsocket $manager */
$manager = Snowflake::get()->annotation->get('websocket'); $manager = Snowflake::app()->annotation->get('websocket');
if (!isset($frame->data['route'])) { if (!isset($frame->data['route'])) {
throw new \Exception('Fromat errr.'); throw new \Exception('Fromat errr.');
} }
@@ -47,9 +47,9 @@ class OnMessage extends Callback
$this->addError($exception->getMessage(), 'websocket'); $this->addError($exception->getMessage(), 'websocket');
$server->send($frame->fd, $exception->getMessage()); $server->send($frame->fd, $exception->getMessage());
} finally { } finally {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::EVENT_AFTER_REQUEST); $event->trigger(Event::EVENT_AFTER_REQUEST);
Snowflake::get()->logger->insert(); Snowflake::app()->logger->insert();
} }
} }
+1 -1
View File
@@ -78,7 +78,7 @@ class OnPacket extends Callback
$client[] = $this->pack(['message' => $exception->getMessage()]); $client[] = $this->pack(['message' => $exception->getMessage()]);
return $server->sendto(...$client); return $server->sendto(...$client);
} finally { } finally {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::SERVER_WORKER_STOP); $event->trigger(Event::SERVER_WORKER_STOP);
} }
} }
+1 -1
View File
@@ -28,7 +28,7 @@ class OnPipeMessage extends Callback
public function onHandler(Server $server, int $src_worker_id, $message) public function onHandler(Server $server, int $src_worker_id, $message)
{ {
// TODO: Implement onHandler() method. // TODO: Implement onHandler() method.
$events = Snowflake::get()->getEvent(); $events = Snowflake::app()->getEvent();
if (!$events->exists(Event::PIPE_MESSAGE)) { if (!$events->exists(Event::PIPE_MESSAGE)) {
return; return;
} }
+1 -1
View File
@@ -78,7 +78,7 @@ class OnReceive extends Callback
$client[] = $this->pack(['message' => $exception->getMessage()]); $client[] = $this->pack(['message' => $exception->getMessage()]);
return $server->send(...$client); return $server->send(...$client);
} finally { } finally {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::SERVER_WORKER_STOP); $event->trigger(Event::SERVER_WORKER_STOP);
} }
} }
+3 -3
View File
@@ -39,11 +39,11 @@ class OnRequest extends Callback
if ($sRequest->is('favicon.ico')) { if ($sRequest->is('favicon.ico')) {
return $sResponse->send($sRequest->isNotFound(), 200); return $sResponse->send($sRequest->isNotFound(), 200);
} }
$sResponse->send(Snowflake::get()->router->dispatch(), 200); $sResponse->send(Snowflake::app()->router->dispatch(), 200);
} catch (Error | \Throwable $exception) { } catch (Error | \Throwable $exception) {
$this->sendErrorMessage($sResponse ?? null, $exception, $response); $this->sendErrorMessage($sResponse ?? null, $exception, $response);
} finally { } finally {
$events = Snowflake::get()->getEvent(); $events = Snowflake::app()->getEvent();
if (!$events->exists(Event::EVENT_AFTER_REQUEST)) { if (!$events->exists(Event::EVENT_AFTER_REQUEST)) {
return; return;
} }
@@ -85,7 +85,7 @@ class OnRequest extends Callback
$code = $exception->getCode() ?? 500; $code = $exception->getCode() ?? 500;
$trance = array_slice($exception->getTrace(), 0, 10); $trance = array_slice($exception->getTrace(), 0, 10);
Snowflake::get()->logger->write(print_r($trance, true), 'exception'); Snowflake::app()->logger->write(print_r($trance, true), 'exception');
return JSON::to($code, $errorInfo['message']); return JSON::to($code, $errorInfo['message']);
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class OnShutdown extends Callback
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
$this->system_mail('server shutdown~'); $this->system_mail('server shutdown~');
$event = Snowflake::get()->getEvent(); $event = Snowflake::app()->getEvent();
if (!$event->exists(Event::SERVER_SHUTDOWN)) { if (!$event->exists(Event::SERVER_SHUTDOWN)) {
return; return;
} }
+1 -1
View File
@@ -21,7 +21,7 @@ class OnStart extends Callback
$time = storage('socket.sock'); $time = storage('socket.sock');
Snowflake::writeFile($time, $server->master_pid); Snowflake::writeFile($time, $server->master_pid);
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
if ($event->exists(Event::SERVER_EVENT_START)) { if ($event->exists(Event::SERVER_EVENT_START)) {
$event->trigger(Event::SERVER_EVENT_START, null, $server); $event->trigger(Event::SERVER_EVENT_START, null, $server);
} }
+1 -1
View File
@@ -108,7 +108,7 @@ class OnTask extends Callback
$finish['info'] = $this->format($exception); $finish['info'] = $this->format($exception);
$this->error($exception, 'Task'); $this->error($exception, 'Task');
} finally { } finally {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::RELEASE_ALL); $event->trigger(Event::RELEASE_ALL);
Timer::clearAll(); Timer::clearAll();
} }
+2 -2
View File
@@ -52,13 +52,13 @@ class OnWorkerStart extends Callback
{ {
try { try {
$this->debug(sprintf('Worker #%d is start.....', $worker_id)); $this->debug(sprintf('Worker #%d is start.....', $worker_id));
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
if (!$event->exists(Event::SERVER_WORKER_START)) { if (!$event->exists(Event::SERVER_WORKER_START)) {
return; return;
} }
$event->trigger(Event::SERVER_WORKER_START); $event->trigger(Event::SERVER_WORKER_START);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
Snowflake::get()->getLogger()->write($exception->getMessage(), 'worker'); Snowflake::app()->getLogger()->write($exception->getMessage(), 'worker');
} }
} }
+2 -2
View File
@@ -153,7 +153,7 @@ class Response extends Application
$string .= 'Command Success!' . PHP_EOL; $string .= 'Command Success!' . PHP_EOL;
echo $string; echo $string;
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger('CONSOLE_END'); $event->trigger('CONSOLE_END');
return 'ok'; return 'ok';
@@ -198,7 +198,7 @@ class Response extends Application
*/ */
public static function create($response = null) public static function create($response = null)
{ {
$ciResponse = Snowflake::get()->clone('response'); $ciResponse = Snowflake::app()->clone('response');
$ciResponse->response = $response; $ciResponse->response = $response;
$ciResponse->startTime = microtime(true); $ciResponse->startTime = microtime(true);
$ciResponse->format = self::JSON; $ciResponse->format = self::JSON;
+1 -1
View File
@@ -24,7 +24,7 @@ class Handler extends Application
*/ */
public function __construct() public function __construct()
{ {
$this->router = Snowflake::get()->router; $this->router = Snowflake::app()->router;
parent::__construct([]); parent::__construct([]);
} }
+2 -2
View File
@@ -150,7 +150,7 @@ class Node extends Application
} }
/** @var Annotation $annotation */ /** @var Annotation $annotation */
$annotation = Snowflake::get()->annotation->get('http'); $annotation = Snowflake::app()->annotation->get('http');
if (!empty($annotations = $annotation->getAnnotation(Annotation::class))) { if (!empty($annotations = $annotation->getAnnotation(Annotation::class))) {
$this->_interceptors = $annotation->read($reflect, $action, $annotations); $this->_interceptors = $annotation->read($reflect, $action, $annotations);
} }
@@ -273,7 +273,7 @@ class Node extends Application
*/ */
public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false) public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false)
{ {
$limits = Snowflake::get()->getLimits(); $limits = Snowflake::app()->getLimits();
$limits->addLimits($this->path, $limit, $duration, $isBindConsumer); $limits->addLimits($this->path, $limit, $duration, $isBindConsumer);
return $this; return $this;
} }
+1 -1
View File
@@ -472,7 +472,7 @@ class Router extends Application implements RouterInterface
$prefix = APP_PATH . 'app/Http/'; $prefix = APP_PATH . 'app/Http/';
/** @var Annotation $annotation */ /** @var Annotation $annotation */
$annotation = Snowflake::get()->annotation; $annotation = Snowflake::app()->annotation;
$annotation->register('http', Annotation::class); $annotation->register('http', Annotation::class);
$annotation = $annotation->get('http'); $annotation = $annotation->get('http');
+7 -7
View File
@@ -68,7 +68,7 @@ class Server extends Application
*/ */
public function initCore(array $configs) public function initCore(array $configs)
{ {
$annotation = Snowflake::get()->annotation; $annotation = Snowflake::app()->annotation;
$annotation->register('tcp', Tcp::class); $annotation->register('tcp', Tcp::class);
$annotation->register('http', Annotation::class); $annotation->register('http', Annotation::class);
$annotation->register('websocket', AWebsocket::class); $annotation->register('websocket', AWebsocket::class);
@@ -132,7 +132,7 @@ class Server extends Application
return; return;
} }
$application = Snowflake::get(); $application = Snowflake::app();
foreach ($processes as $name => $process) { foreach ($processes as $name => $process) {
$class = Snowflake::createObject($process); $class = Snowflake::createObject($process);
if (!method_exists($class, 'onHandler')) { if (!method_exists($class, 'onHandler')) {
@@ -190,7 +190,7 @@ class Server extends Application
if (!is_array($config['events'])) { if (!is_array($config['events'])) {
return; return;
} }
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
foreach ($config['events'] as $name => $_event) { foreach ($config['events'] as $name => $_event) {
$event->on($name, $_event); $event->on($name, $_event);
} }
@@ -284,8 +284,8 @@ class Server extends Application
*/ */
public function onLoadHttpHandler() public function onLoadHttpHandler()
{ {
$event = Snowflake::get()->getEvent(); $event = Snowflake::app()->getEvent();
$router = Snowflake::get()->getRouter(); $router = Snowflake::app()->getRouter();
if ($event->exists(Event::SERVER_WORKER_START, [$router, 'loadRouterSetting'])) { if ($event->exists(Event::SERVER_WORKER_START, [$router, 'loadRouterSetting'])) {
return; return;
} }
@@ -299,11 +299,11 @@ class Server extends Application
public function onLoadWebsocketHandler() public function onLoadWebsocketHandler()
{ {
/** @var AWebsocket $websocket */ /** @var AWebsocket $websocket */
$websocket = Snowflake::get()->annotation->register('websocket', AWebsocket::class); $websocket = Snowflake::app()->annotation->register('websocket', AWebsocket::class);
$websocket->namespace = 'App\\Websocket'; $websocket->namespace = 'App\\Websocket';
$websocket->path = APP_PATH . 'app/Websocket'; $websocket->path = APP_PATH . 'app/Websocket';
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
if ($event->exists(Event::SERVER_WORKER_START, [$websocket, 'registration_notes'])) { if ($event->exists(Event::SERVER_WORKER_START, [$websocket, 'registration_notes'])) {
return; return;
} }
+2 -2
View File
@@ -26,7 +26,7 @@ trait Server
*/ */
public function __construct($host, $port = null, $mode = null, $sock_type = null) public function __construct($host, $port = null, $mode = null, $sock_type = null)
{ {
$this->application = Snowflake::get(); $this->application = Snowflake::app();
parent::__construct($host, $port, $mode, $sock_type); parent::__construct($host, $port, $mode, $sock_type);
} }
@@ -89,7 +89,7 @@ trait Server
if (!class_exists($classPrefix)) { if (!class_exists($classPrefix)) {
throw new Exception('class not found.'); throw new Exception('class not found.');
} }
$class = Snowflake::createObject($classPrefix, [Snowflake::get()]); $class = Snowflake::createObject($classPrefix, [Snowflake::app()]);
return [$class, 'onHandler']; return [$class, 'onHandler'];
} }
+3 -3
View File
@@ -21,7 +21,7 @@ return [
], ],
'events' => [ 'events' => [
Event::SERVER_WORKER_START => function () { Event::SERVER_WORKER_START => function () {
$router = Snowflake::get()->router; $router = Snowflake::app()->router;
$router->loadRouterSetting(); $router->loadRouterSetting();
}, },
] ]
@@ -81,7 +81,7 @@ return [
'events' => [ 'events' => [
Event::SERVER_WORKER_START => function () { Event::SERVER_WORKER_START => function () {
$path = APP_PATH . 'app/Websocket'; $path = APP_PATH . 'app/Websocket';
$websocket = Snowflake::get()->annotation->websocket; $websocket = Snowflake::app()->annotation->websocket;
$websocket->registration_notes($path, 'App\\Sockets\\'); $websocket->registration_notes($path, 'App\\Sockets\\');
}, },
Event::SERVER_HANDSHAKE => function (Request $request, Response $response) { Event::SERVER_HANDSHAKE => function (Request $request, Response $response) {
@@ -94,7 +94,7 @@ return [
if (is_null($json = json_decode($frame->data, true))) { if (is_null($json = json_decode($frame->data, true))) {
return $server->push($frame->fd, 'format error~'); return $server->push($frame->fd, 'format error~');
} }
$websocket = Snowflake::get()->annotation->websocket; $websocket = Snowflake::app()->annotation->websocket;
if ($websocket->has($json['path'])) { if ($websocket->has($json['path'])) {
return $websocket->runWith($json['path'], [$frame->fd, $json]); return $websocket->runWith($json['path'], [$frame->fd, $json]);
} else { } else {
+3 -3
View File
@@ -74,7 +74,7 @@ class Component extends BaseObject
*/ */
public function trigger($name, $event = null, $params = [], $isRemove = false) public function trigger($name, $event = null, $params = [], $isRemove = false)
{ {
$aEvents = Snowflake::get()->event; $aEvents = Snowflake::app()->event;
if (isset($this->_events[$name])) { if (isset($this->_events[$name])) {
$events = $this->_events[$name]; $events = $this->_events[$name];
foreach ($events as $key => $_event) { foreach ($events as $key => $_event) {
@@ -98,7 +98,7 @@ class Component extends BaseObject
*/ */
public function off($name, $handler = NULL) public function off($name, $handler = NULL)
{ {
$aEvents = Snowflake::get()->event; $aEvents = Snowflake::app()->event;
if (!isset($this->_events[$name])) { if (!isset($this->_events[$name])) {
return $aEvents->of($name, $handler); return $aEvents->of($name, $handler);
} }
@@ -125,7 +125,7 @@ class Component extends BaseObject
public function offAll() public function offAll()
{ {
$this->_events = []; $this->_events = [];
$aEvents = Snowflake::get()->event; $aEvents = Snowflake::app()->event;
$aEvents->clean(); $aEvents->clean();
} }
+3 -3
View File
@@ -33,7 +33,7 @@ class Config extends Component
*/ */
public static function get($key, $try = FALSE, $default = null) public static function get($key, $try = FALSE, $default = null)
{ {
$config = Snowflake::get()->config; $config = Snowflake::app()->config;
if (strpos($key, '.') === false) { if (strpos($key, '.') === false) {
if (isset($config->data[$key])) { if (isset($config->data[$key])) {
@@ -74,7 +74,7 @@ class Config extends Component
*/ */
public static function set($key, $value) public static function set($key, $value)
{ {
$config = Snowflake::get()->config; $config = Snowflake::app()->config;
return $config->data[$key] = $value; return $config->data[$key] = $value;
} }
@@ -85,7 +85,7 @@ class Config extends Component
*/ */
public static function has($key, $must_not_null = false) public static function has($key, $must_not_null = false)
{ {
$config = Snowflake::get()->config; $config = Snowflake::app()->config;
if (!isset($config->data[$key])) { if (!isset($config->data[$key])) {
return false; return false;
} }
+1 -1
View File
@@ -67,7 +67,7 @@ class Application extends BaseApplication
*/ */
public function start() public function start()
{ {
$manager = Snowflake::get()->server; $manager = Snowflake::app()->server;
$manager->start(); $manager->start();
} }
+4 -4
View File
@@ -264,7 +264,7 @@ class Redis extends Component
*/ */
public function init() public function init()
{ {
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->on(Event::RELEASE_ALL, [$this, 'destroy']); $event->on(Event::RELEASE_ALL, [$this, 'destroy']);
$event->on(Event::EVENT_AFTER_REQUEST, [$this, 'release']); $event->on(Event::EVENT_AFTER_REQUEST, [$this, 'release']);
} }
@@ -296,7 +296,7 @@ class Redis extends Component
*/ */
public function release() public function release()
{ {
$connections = Snowflake::get()->pool->redis; $connections = Snowflake::app()->pool->redis;
$connections->release($this->get_config(), true); $connections->release($this->get_config(), true);
} }
@@ -305,7 +305,7 @@ class Redis extends Component
*/ */
public function destroy() public function destroy()
{ {
$connections = Snowflake::get()->pool->redis; $connections = Snowflake::app()->pool->redis;
$connections->destroy($this->get_config(), true); $connections->destroy($this->get_config(), true);
} }
@@ -315,7 +315,7 @@ class Redis extends Component
*/ */
public function proxy() public function proxy()
{ {
$connections = Snowflake::get()->pool->redis; $connections = Snowflake::app()->pool->redis;
$config = $this->get_config(); $config = $this->get_config();
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
+5 -5
View File
@@ -75,7 +75,7 @@ class ErrorHandler extends Component implements ErrorInterface
{ {
$this->category = 'exception'; $this->category = 'exception';
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::RELEASE_ALL); $event->trigger(Event::RELEASE_ALL);
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
@@ -101,9 +101,9 @@ class ErrorHandler extends Component implements ErrorInterface
$data = JSON::to(500, 'Error : ' . $error[1], $path); $data = JSON::to(500, 'Error : ' . $error[1], $path);
Snowflake::get()->getLogger()->error($data, 'error'); Snowflake::app()->getLogger()->error($data, 'error');
$event = Snowflake::get()->event; $event = Snowflake::app()->event;
$event->trigger(Event::RELEASE_ALL); $event->trigger(Event::RELEASE_ALL);
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]); throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
@@ -123,7 +123,7 @@ class ErrorHandler extends Component implements ErrorInterface
$data = JSON::to($code, $this->category . ': ' . $message, $path); $data = JSON::to($code, $this->category . ': ' . $message, $path);
Snowflake::get()->getLogger()->trance($data, $this->category); Snowflake::app()->getLogger()->trance($data, $this->category);
return response()->send($data); return response()->send($data);
} }
@@ -154,6 +154,6 @@ class ErrorHandler extends Component implements ErrorInterface
*/ */
public function writer($message, $category = 'app') public function writer($message, $category = 'app')
{ {
Snowflake::get()->getLogger()->debug($message, $category); Snowflake::app()->getLogger()->debug($message, $category);
} }
} }
+1 -1
View File
@@ -109,7 +109,7 @@ class Logger extends Component
public function print_r($message, $category = '') public function print_r($message, $category = '')
{ {
/** @var Process $logger */ /** @var Process $logger */
$logger = Snowflake::get()->logger; $logger = Snowflake::app()->logger;
$logger->write(JSON::encode([$message, $category])); $logger->write(JSON::encode([$message, $category]));
} }
+1 -1
View File
@@ -63,7 +63,7 @@ class Event extends BaseObject
$this->_events[$name] = []; $this->_events[$name] = [];
} }
if ($callback instanceof \Closure) { if ($callback instanceof \Closure) {
$callback = \Closure::bind($callback, Snowflake::get()); $callback = \Closure::bind($callback, Snowflake::app());
} else if (is_array($callback) && is_string($callback[0])) { } else if (is_array($callback) && is_string($callback[0])) {
if (!class_exists($callback[0])) { if (!class_exists($callback[0])) {
throw new \Exception('Undefined callback class.'); throw new \Exception('Undefined callback class.');
+1 -1
View File
@@ -431,7 +431,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
*/ */
private function getRedis() private function getRedis()
{ {
return Snowflake::get()->getRedis(); return Snowflake::app()->getRedis();
} }
} }
+2 -2
View File
@@ -20,7 +20,7 @@ class Pool extends \Snowflake\Abstracts\Pool
*/ */
public function getRedis() public function getRedis()
{ {
return Snowflake::get()->redis_connections; return Snowflake::app()->redis_connections;
} }
/** /**
@@ -28,7 +28,7 @@ class Pool extends \Snowflake\Abstracts\Pool
*/ */
public function getDb() public function getDb()
{ {
return Snowflake::get()->connections; return Snowflake::app()->connections;
} }
} }
+1 -1
View File
@@ -173,7 +173,7 @@ class ServerInotify extends Process
public function trigger_reload() public function trigger_reload()
{ {
/** @var Server $server */ /** @var Server $server */
$server = Snowflake::get()->get('server')->getServer(); $server = Snowflake::app()->get('server')->getServer();
$server->reload(); $server->reload();
} }
+1 -1
View File
@@ -34,7 +34,7 @@ class Snowflake
/** /**
* @return mixed * @return mixed
*/ */
public static function get() public static function app()
{ {
return static::$service; return static::$service;
} }