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