This commit is contained in:
2020-12-24 11:12:23 +08:00
parent 5a7c7176dc
commit f18031c2c0
18 changed files with 39 additions and 39 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ namespace Database\Base;
use HttpServer\Http\Context; use HttpServer\Http\Context;
use ReflectionException; use ReflectionException;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Database\ActiveQuery; use Database\ActiveQuery;
use Database\ActiveRecord; use Database\ActiveRecord;
use Database\Connection; use Database\Connection;
+3 -3
View File
@@ -15,7 +15,7 @@ namespace Database\Mysql;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Database\Connection; use Database\Connection;
use Exception; use Exception;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
/** /**
* Class Columns * Class Columns
@@ -115,7 +115,7 @@ class Columns extends Component
if ($this->isInt($format)) { if ($this->isInt($format)) {
return (int)$val; return (int)$val;
} else if ($this->isJson($format)) { } else if ($this->isJson($format)) {
return JSON::decode($val, true); return Json::decode($val, true);
} else if ($this->isFloat($format)) { } else if ($this->isFloat($format)) {
return (float)$val; return (float)$val;
} else { } else {
@@ -151,7 +151,7 @@ class Columns extends Component
if ($this->isInt($format)) { if ($this->isInt($format)) {
return (int)$val; return (int)$val;
} else if ($this->isJson($format)) { } else if ($this->isJson($format)) {
return JSON::encode($val); return Json::encode($val);
} else if ($this->isFloat($format)) { } else if ($this->isFloat($format)) {
return (float)$val; return (float)$val;
} else { } else {
+2 -2
View File
@@ -5,7 +5,7 @@ namespace Database\Orm;
use ReflectionException; use ReflectionException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Core\Str; use Snowflake\Core\Str;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -205,7 +205,7 @@ trait Condition
if (is_numeric($value)) { if (is_numeric($value)) {
return $value; return $value;
} else { } else {
if (!is_null(JSON::decode($value))) { if (!is_null(Json::decode($value))) {
return $value; return $value;
} }
return '\'' . Str::encode($value) . '\''; return '\'' . Str::encode($value) . '\'';
+1 -1
View File
@@ -9,7 +9,7 @@ use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\Help; use Snowflake\Core\Help;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Swoole\Coroutine\System; use Swoole\Coroutine\System;
+2 -2
View File
@@ -8,7 +8,7 @@ use Exception;
use HttpServer\Http\Context; use HttpServer\Http\Context;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\Help; use Snowflake\Core\Help;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Swoole\Http2\Request; use Swoole\Http2\Request;
use Swoole\Coroutine\Http2\Client as H2Client; use Swoole\Coroutine\Http2\Client as H2Client;
@@ -107,7 +107,7 @@ class Http2 extends Component
'accept-encoding' => 'gzip' 'accept-encoding' => 'gzip'
]; ];
if (!is_string($params)) { if (!is_string($params)) {
$params = JSON::encode($params); $params = Json::encode($params);
} }
Context::setContext($domain . $path, $req); Context::setContext($domain . $path, $req);
} }
+2 -2
View File
@@ -10,7 +10,7 @@ use HttpServer\Exception\ExitException;
use HttpServer\Http\Request as HRequest; use HttpServer\Http\Request as HRequest;
use HttpServer\Http\Response as HResponse; use HttpServer\Http\Response as HResponse;
use ReflectionException; use ReflectionException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Event; use Snowflake\Event;
use Snowflake\Exception\ComponentException; use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
@@ -68,7 +68,7 @@ class OnRequest extends Callback
$request = get_object_vars($request); $request = get_object_vars($request);
$logger->write(JSON::encode($request), 'request'); $logger->write(Json::encode($request), 'request');
} }
} }
+3 -3
View File
@@ -7,7 +7,7 @@ namespace HttpServer\Events\Utility;
use Closure; use Closure;
use Exception; use Exception;
use ReflectionException; use ReflectionException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -26,7 +26,7 @@ class DataResolve
public static function pack($unpack, $data) public static function pack($unpack, $data)
{ {
if (empty($unpack)) { if (empty($unpack)) {
$params = JSON::encode($data); $params = Json::encode($data);
} else { } else {
$params = self::callbackResolve($unpack, null, null, $data); $params = self::callbackResolve($unpack, null, null, $data);
} }
@@ -49,7 +49,7 @@ class DataResolve
public static function unpack($unpack, $address, $port, $data) public static function unpack($unpack, $address, $port, $data)
{ {
if (empty($unpack)) { if (empty($unpack)) {
$params = JSON::decode($data); $params = Json::decode($data);
} else { } else {
$params = self::callbackResolve($unpack, $address, $port, $data); $params = self::callbackResolve($unpack, $address, $port, $data);
} }
+2 -2
View File
@@ -11,7 +11,7 @@ namespace HttpServer\Http\Formatter;
use Exception; use Exception;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use HttpServer\Application; use HttpServer\Application;
use Swoole\Http\Response; use Swoole\Http\Response;
use HttpServer\IInterface\IFormatter; use HttpServer\IInterface\IFormatter;
@@ -38,7 +38,7 @@ class HtmlFormatter extends Application implements IFormatter
public function send($context): static public function send($context): static
{ {
if (!is_string($context)) { if (!is_string($context)) {
$context = JSON::encode($context); $context = Json::encode($context);
} }
$this->data = $context; $this->data = $context;
return $this; return $this;
+4 -4
View File
@@ -12,7 +12,7 @@ namespace HttpServer\Http;
use Exception; use Exception;
use HttpServer\Exception\RequestException; use HttpServer\Exception\RequestException;
use Snowflake\Core\Help; use Snowflake\Core\Help;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Snowflake; use Snowflake\Snowflake;
/** /**
@@ -130,11 +130,11 @@ class HttpParams
{ {
$data = $this->array($name); $data = $this->array($name);
if (empty($data)) { if (empty($data)) {
return JSON::encode([]); return Json::encode([]);
} else if (!is_array($data)) { } else if (!is_array($data)) {
return JSON::encode([]); return Json::encode([]);
} }
return JSON::encode($data); return Json::encode($data);
} }
/** /**
+2 -2
View File
@@ -8,7 +8,7 @@ use HttpServer\Application;
use HttpServer\IInterface\AuthIdentity; use HttpServer\IInterface\AuthIdentity;
use ReflectionException; use ReflectionException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Exception\ComponentException; use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -415,7 +415,7 @@ class Request extends Application
*/ */
public function isNotFound(): bool public function isNotFound(): bool
{ {
return JSON::to(404, 'Page ' . $this->getUri() . ' not found.'); return Json::to(404, 'Page ' . $this->getUri() . ' not found.');
} }
+2 -2
View File
@@ -11,7 +11,7 @@ use Exception;
use HttpServer\Application; use HttpServer\Application;
use ReflectionException; use ReflectionException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\Coroutine; use Swoole\Coroutine;
@@ -440,7 +440,7 @@ class Node extends Application
{ {
$this->restructure(); $this->restructure();
if (empty($this->callback)) { if (empty($this->callback)) {
return JSON::to(404, $node->_error ?? 'Page not found.'); return Json::to(404, $node->_error ?? 'Page not found.');
} }
$requestParams = func_get_args(); $requestParams = func_get_args();
if (func_num_args() > 0) { if (func_num_args() > 0) {
+4 -4
View File
@@ -37,10 +37,10 @@ return [
], ],
'message' => [ 'message' => [
'pack' => function ($data) { 'pack' => function ($data) {
return \Snowflake\Core\JSON::encode($data); return \Snowflake\Core\Json::encode($data);
}, },
'unpack' => function ($data) { 'unpack' => function ($data) {
return \Snowflake\Core\JSON::decode($data); return \Snowflake\Core\Json::decode($data);
}, },
], ],
'events' => [ 'events' => [
@@ -57,10 +57,10 @@ return [
], ],
'message' => [ 'message' => [
'pack' => function ($data) { 'pack' => function ($data) {
return \Snowflake\Core\JSON::encode($data); return \Snowflake\Core\Json::encode($data);
}, },
'unpack' => function ($data) { 'unpack' => function ($data) {
return \Snowflake\Core\JSON::decode($data); return \Snowflake\Core\Json::decode($data);
}, },
], ],
'events' => [ 'events' => [
+2 -2
View File
@@ -6,7 +6,7 @@ namespace Snowflake\Abstracts;
use Exception; use Exception;
use HttpServer\Exception\ExitException; use HttpServer\Exception\ExitException;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
/** /**
* Class BaseGoto * Class BaseGoto
@@ -23,7 +23,7 @@ class BaseGoto extends Component
*/ */
public function end(string $message, $statusCode = 200): mixed public function end(string $message, $statusCode = 200): mixed
{ {
throw new ExitException(JSON::to(12350, $message), $statusCode); throw new ExitException(Json::to(12350, $message), $statusCode);
} }
} }
+1 -1
View File
@@ -93,7 +93,7 @@ class Help
if (!is_string($parameter)) { if (!is_string($parameter)) {
$parameter = ArrayAccess::toArray($parameter); $parameter = ArrayAccess::toArray($parameter);
if (is_array($parameter)) { if (is_array($parameter)) {
$parameter = JSON::encode($parameter); $parameter = Json::encode($parameter);
} }
} }
return $parameter; return $parameter;
@@ -16,7 +16,7 @@ use Exception;
* Class JSON * Class JSON
* @package Snowflake\Snowflake\Core * @package Snowflake\Snowflake\Core
*/ */
class JSON class Json
{ {
/** /**
+3 -3
View File
@@ -12,7 +12,7 @@ namespace Snowflake\Error;
use Exception; use Exception;
use HttpServer\IInterface\IFormatter; use HttpServer\IInterface\IFormatter;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Event; use Snowflake\Event;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -98,7 +98,7 @@ class ErrorHandler extends Component implements ErrorInterface
$error[0] = 500; $error[0] = 500;
} }
$data = JSON::to(500, $error[1], $path); $data = Json::to(500, $error[1], $path);
logger()->error($data, 'error'); logger()->error($data, 'error');
@@ -120,7 +120,7 @@ class ErrorHandler extends Component implements ErrorInterface
{ {
$path = ['file' => $file, 'line' => $line]; $path = ['file' => $file, 'line' => $line];
$data = JSON::to($code, $this->category . ': ' . $message, $path); $data = Json::to($code, $this->category . ': ' . $message, $path);
logger()->trance($data, $this->category); logger()->trance($data, $this->category);
+2 -2
View File
@@ -12,7 +12,7 @@ namespace Snowflake\Error;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\Process; use Swoole\Process;
use Throwable; use Throwable;
@@ -258,7 +258,7 @@ class Logger extends Component
$logger->write($string . $exception->getTraceAsString(), 'trace'); $logger->write($string . $exception->getTraceAsString(), 'trace');
$logger->write(jTraceEx($exception), 'exception'); $logger->write(jTraceEx($exception), 'exception');
return JSON::to($code, $errorInfo['message'], [ return Json::to($code, $errorInfo['message'], [
'file' => $exception->getFile(), 'file' => $exception->getFile(),
'line' => $exception->getLine() 'line' => $exception->getLine()
]); ]);
+2 -2
View File
@@ -10,7 +10,7 @@ use HttpServer\IInterface\Task;
use ReflectionException; use ReflectionException;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Core\JSON; use Snowflake\Core\Json;
use Snowflake\Di\Container; use Snowflake\Di\Container;
use Snowflake\Exception\ComponentException; use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
@@ -257,7 +257,7 @@ class Snowflake
return false; return false;
} }
if (!is_string($data)) { if (!is_string($data)) {
$data = JSON::encode($data); $data = Json::encode($data);
} }
return $server->push($fd, $data); return $server->push($fd, $data);
} }