mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
PHP80 小修 (#187)
* migrate-php80 fix styles fix static analyse * fix some bugs
This commit is contained in:
@@ -37,7 +37,7 @@ class ConnectionUtil
|
||||
// 这里下面为连接准入,允许接入反向 WS
|
||||
if (ProcessStateManager::$process_mode['worker'] > 1) {
|
||||
// 文件名格式为 .WS{fd}.{pid},文件内容是 impl 名称的 JSON 格式
|
||||
file_put_contents(zm_dir(ZM_STATE_DIR . '/.WS' . $fd . '.' . ProcessManager::getProcessId()), json_encode($handle));
|
||||
file_put_contents(zm_dir(ZM_STATE_DIR . '/.WS' . $fd . '.' . ProcessManager::getProcessId()), json_encode($handle, JSON_THROW_ON_ERROR));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class ConnectionUtil
|
||||
// 这里下面为连接准入,允许接入反向 WS
|
||||
if (ProcessStateManager::$process_mode['worker'] > 1) {
|
||||
// 文件名格式为 .WS{fd}.{pid},文件内容是 impl 名称的 JSON 格式
|
||||
file_put_contents(zm_dir(ZM_STATE_DIR . '/.WS' . $fd . '.' . ProcessManager::getProcessId()), json_encode(self::$connection_handles[$fd]));
|
||||
file_put_contents(zm_dir(ZM_STATE_DIR . '/.WS' . $fd . '.' . ProcessManager::getProcessId()), json_encode(self::$connection_handles[$fd], JSON_THROW_ON_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,7 @@ use ZM\Store\FileSystem;
|
||||
*/
|
||||
class HttpUtil
|
||||
{
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
private static $routes;
|
||||
private static ?RouteCollection $routes = null;
|
||||
|
||||
/**
|
||||
* 解析 Uri,用于匹配路由用的
|
||||
@@ -42,10 +39,10 @@ class HttpUtil
|
||||
// 使用UrlMatcher进行匹配Url
|
||||
$matcher = new UrlMatcher(static::getRouteCollection(), $context);
|
||||
$matched = $matcher->match($request->getUri()->getPath());
|
||||
} catch (ResourceNotFoundException $e) {
|
||||
} catch (ResourceNotFoundException) {
|
||||
// 路由找不到会抛出异常,我们不需要这个异常,转换为状态码
|
||||
return ZM_ERR_ROUTE_NOT_FOUND;
|
||||
} catch (MethodNotAllowedException $e) {
|
||||
} catch (MethodNotAllowedException) {
|
||||
// 路由匹配到了,但该路由不能使用该方法,所以返回状态码(路由不允许)
|
||||
return ZM_ERR_ROUTE_METHOD_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
@@ -43,16 +43,14 @@ class ReflectionUtil
|
||||
|
||||
/**
|
||||
* 将传入变量转换为字符串
|
||||
*
|
||||
* @param mixed $var
|
||||
*/
|
||||
public static function variableToString($var): string
|
||||
public static function variableToString(mixed $var): string
|
||||
{
|
||||
switch (true) {
|
||||
case is_callable($var):
|
||||
if (is_array($var)) {
|
||||
if (is_object($var[0])) {
|
||||
return get_class($var[0]) . '@' . $var[1];
|
||||
return $var[0]::class . '@' . $var[1];
|
||||
}
|
||||
return $var[0] . '::' . $var[1];
|
||||
}
|
||||
@@ -60,9 +58,9 @@ class ReflectionUtil
|
||||
case is_string($var):
|
||||
return $var;
|
||||
case is_array($var):
|
||||
return 'array' . json_encode($var);
|
||||
return 'array' . json_encode($var, JSON_THROW_ON_ERROR);
|
||||
case is_object($var):
|
||||
return get_class($var);
|
||||
return $var::class;
|
||||
case is_resource($var):
|
||||
return 'resource(' . get_resource_type($var) . ')';
|
||||
case is_null($var):
|
||||
@@ -83,7 +81,7 @@ class ReflectionUtil
|
||||
* @param callable|string $callback 回调
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function isNonStaticMethod($callback): bool
|
||||
public static function isNonStaticMethod(callable|array|string $callback): bool
|
||||
{
|
||||
if (is_array($callback) && is_string($callback[0])) {
|
||||
$reflection = new \ReflectionMethod($callback[0], $callback[1]);
|
||||
@@ -103,7 +101,7 @@ class ReflectionUtil
|
||||
* @param callable|string $callback 回调
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function getCallReflector($callback): \ReflectionFunctionAbstract
|
||||
public static function getCallReflector(callable|string $callback): \ReflectionFunctionAbstract
|
||||
{
|
||||
if (is_string($callback) && str_contains($callback, '::')) {
|
||||
$callback = explode('::', $callback);
|
||||
|
||||
@@ -12,6 +12,6 @@ class ZMUtil
|
||||
*/
|
||||
public static function getComposerMetadata(?string $path = null): ?array
|
||||
{
|
||||
return json_decode(file_get_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json'), true);
|
||||
return json_decode(file_get_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user