2020-08-31 01:27:08 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2021-03-05 16:36:18 +08:00
|
|
|
|
defined('APP_PATH') or define('APP_PATH', realpath(__DIR__ . '/../../'));
|
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
2021-02-22 17:44:24 +08:00
|
|
|
|
use Annotation\Annotation;
|
2021-04-07 14:15:50 +08:00
|
|
|
|
use HttpServer\Http\Context;
|
2021-01-15 15:53:10 +08:00
|
|
|
|
use HttpServer\Http\HttpParams;
|
|
|
|
|
|
use HttpServer\Http\Request;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
use HttpServer\Http\Response;
|
2020-10-29 18:17:25 +08:00
|
|
|
|
use HttpServer\Route\Router;
|
2021-03-28 16:09:18 +08:00
|
|
|
|
use HttpServer\Service\Http;
|
|
|
|
|
|
use HttpServer\Service\Packet;
|
|
|
|
|
|
use HttpServer\Service\Receive;
|
|
|
|
|
|
use HttpServer\Service\Websocket;
|
2021-03-05 16:57:12 +08:00
|
|
|
|
use JetBrains\PhpStorm\Pure;
|
2021-03-09 19:40:10 +08:00
|
|
|
|
use Snowflake\Abstracts\Config;
|
2021-03-30 11:56:29 +08:00
|
|
|
|
use Snowflake\Application;
|
2021-04-07 14:15:50 +08:00
|
|
|
|
use Snowflake\Core\ArrayAccess;
|
2021-07-06 17:36:26 +08:00
|
|
|
|
use Snowflake\Core\Json;
|
2020-09-11 15:01:22 +08:00
|
|
|
|
use Snowflake\Error\Logger;
|
2021-04-27 15:57:50 +08:00
|
|
|
|
use Snowflake\Event;
|
2021-03-29 11:32:01 +08:00
|
|
|
|
use Snowflake\Exception\ConfigException;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
use Snowflake\Snowflake;
|
2021-03-31 18:19:45 +08:00
|
|
|
|
use Swoole\WebSocket\Server;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
if (!function_exists('make')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
* @param $default
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
* @throws
|
|
|
|
|
|
*/
|
|
|
|
|
|
function make($name, $default = null): mixed
|
|
|
|
|
|
{
|
|
|
|
|
|
if (class_exists($name)) {
|
|
|
|
|
|
return Snowflake::createObject($name);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Snowflake::has($name)) {
|
|
|
|
|
|
return Snowflake::app()->get($name);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (empty($default)) {
|
|
|
|
|
|
throw new Exception("Unknown component ID: $name");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Snowflake::has($default)) {
|
|
|
|
|
|
return Snowflake::app()->get($default);
|
|
|
|
|
|
}
|
|
|
|
|
|
$class = Snowflake::createObject($default);
|
|
|
|
|
|
class_alias($name, $default, true);
|
|
|
|
|
|
return $class;
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
2020-09-15 19:26:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-27 04:48:44 +08:00
|
|
|
|
if (!function_exists('workerName')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
function workerName($worker_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $worker_id >= Snowflake::app()->getSwoole()->setting['worker_num'] ? 'Task' : 'Worker';
|
|
|
|
|
|
}
|
2021-02-27 04:48:44 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
2021-02-22 17:44:24 +08:00
|
|
|
|
if (!function_exists('annotation')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Annotation
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function annotation(): Annotation
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::getAnnotation();
|
|
|
|
|
|
}
|
2021-03-03 19:05:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-08 11:24:31 +08:00
|
|
|
|
if (!function_exists('scan_directory')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param $dir
|
|
|
|
|
|
* @param $namespace
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function scan_directory($dir, $namespace)
|
|
|
|
|
|
{
|
2021-04-28 10:43:16 +08:00
|
|
|
|
$annotation = Snowflake::app()->getAnnotation();
|
|
|
|
|
|
$annotation->read($dir, $namespace);
|
|
|
|
|
|
$annotation->runtime($dir, $namespace);
|
2021-04-08 11:24:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-31 18:19:45 +08:00
|
|
|
|
if (!function_exists('swoole')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Server|null
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function swoole(): ?Server
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::getWebSocket();
|
|
|
|
|
|
}
|
2021-03-31 18:19:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-05 16:57:12 +08:00
|
|
|
|
if (!function_exists('directory')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
#[Pure] function directory($name): string
|
|
|
|
|
|
{
|
|
|
|
|
|
return realpath(APP_PATH . $name);
|
|
|
|
|
|
}
|
2021-03-05 16:57:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-23 16:28:54 +08:00
|
|
|
|
if (!function_exists('isUrl')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @param bool $get_info
|
|
|
|
|
|
* @return false|array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function isUrl($url, $get_info = true): bool|array
|
|
|
|
|
|
{
|
|
|
|
|
|
$queryMatch = '/((http[s]?):\/\/)?(([\w\-\_]+\.)+\w+(:\d+)?)(\/.*)?/';
|
|
|
|
|
|
if (!preg_match($queryMatch, $url, $outPut)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
$port = str_replace(':', '', $outPut[5]);
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
[$isHttps, $domain, $port, $path] = [$outPut[2] == 'https', $outPut[3], $port, $outPut[6] ?? ''];
|
|
|
|
|
|
if ($isHttps && empty($port)) {
|
|
|
|
|
|
$port = 443;
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
unset($outPut);
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
return [$isHttps == 'https', $domain, $port, $path];
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('split_request_uri')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @return false|array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function split_request_uri($url): bool|array
|
|
|
|
|
|
{
|
|
|
|
|
|
if (($parse = isUrl($url, null)) === false) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
[$isHttps, $domain, $port, $path] = $parse;
|
|
|
|
|
|
$uri = $isHttps ? 'https://' . $domain : 'http://' . $domain;
|
|
|
|
|
|
if (!empty($port)) {
|
|
|
|
|
|
$uri .= ':' . $port;
|
|
|
|
|
|
}
|
|
|
|
|
|
return [$uri, $path];
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('hadDomain')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @return false|array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function hadDomain($url): bool|array
|
|
|
|
|
|
{
|
|
|
|
|
|
$param = split_request_uri($url);
|
|
|
|
|
|
return !is_array($param) ? false : $param[0];
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('isDomain')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @return false|array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function isDomain($url): array|bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return !isIp($url);
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!function_exists('isIp')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @return false|array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function isIp($url): bool|array
|
|
|
|
|
|
{
|
|
|
|
|
|
return preg_match('/(\d{1,3}\.){3}\.\d{1,3}(:\d{1,5})?/', $url);
|
|
|
|
|
|
}
|
2020-09-23 16:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-15 19:26:44 +08:00
|
|
|
|
if (!function_exists('loadByDir')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $namespace
|
|
|
|
|
|
* @param $dirname
|
|
|
|
|
|
*/
|
|
|
|
|
|
function classAutoload($namespace, $dirname)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (glob(rtrim($dirname, '/') . '/*') as $value) {
|
|
|
|
|
|
$value = realpath($value);
|
|
|
|
|
|
if (is_dir($value)) {
|
|
|
|
|
|
classAutoload($namespace, $value);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$pos = strpos($value, '.php');
|
|
|
|
|
|
if ($pos === false || strlen($value) - 4 != $pos) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-09-15 20:11:41 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$replace = ltrim(str_replace(__DIR__, '', $value), '/');
|
|
|
|
|
|
$replace = str_replace('.php', '', $replace);
|
2020-09-15 20:11:41 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$first = explode(DIRECTORY_SEPARATOR, $replace);
|
|
|
|
|
|
array_shift($first);
|
2020-09-15 20:11:41 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
Snowflake::setAutoload($namespace . '\\' . implode('\\', $first), $value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-15 19:26:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-16 20:23:23 +08:00
|
|
|
|
if (!function_exists('write')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param string $messages
|
|
|
|
|
|
* @param string $category
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function write(string $messages, $category = 'app')
|
|
|
|
|
|
{
|
|
|
|
|
|
$logger = Snowflake::app()->getLogger();
|
|
|
|
|
|
$logger->write($messages, $category);
|
|
|
|
|
|
}
|
2021-04-03 02:31:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('redis')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
2021-04-08 11:24:31 +08:00
|
|
|
|
* @return \Snowflake\Cache\Redis|Redis
|
2021-04-07 14:15:50 +08:00
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function redis(): \Snowflake\Cache\Redis|Redis
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->getRedis();
|
|
|
|
|
|
}
|
2020-09-16 20:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-30 11:04:04 +08:00
|
|
|
|
if (!function_exists('fire')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param string $event
|
|
|
|
|
|
* @param array $params
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function fire(string $event, array $params = [])
|
|
|
|
|
|
{
|
2021-04-27 15:57:50 +08:00
|
|
|
|
Event::trigger($event, $params);
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2020-10-30 11:04:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-29 03:19:22 +08:00
|
|
|
|
if (!function_exists('aop')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param mixed $handler
|
|
|
|
|
|
* @param array $params
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function aop(mixed $handler, array $params = []): mixed
|
|
|
|
|
|
{
|
2021-04-21 01:46:44 +08:00
|
|
|
|
return Snowflake::app()->get('aop')->dispatch($handler, $params);
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2021-02-23 17:43:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-23 17:19:46 +08:00
|
|
|
|
|
2021-03-30 11:56:29 +08:00
|
|
|
|
if (!function_exists('app')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Application|null
|
|
|
|
|
|
*/
|
|
|
|
|
|
#[Pure] function app(): ?Application
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app();
|
|
|
|
|
|
}
|
2021-03-30 11:56:29 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 20:17:14 +08:00
|
|
|
|
if (!function_exists('instance_load')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
function instance_load()
|
|
|
|
|
|
{
|
|
|
|
|
|
$content = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
|
|
|
|
|
|
if (isset($content['autoload']) && isset($content['autoload']['psr-4'])) {
|
|
|
|
|
|
$psr4 = $content['autoload']['psr-4'];
|
|
|
|
|
|
foreach ($psr4 as $namespace => $dirname) {
|
|
|
|
|
|
classAutoload($namespace, __DIR__ . '/' . $dirname);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-15 20:17:14 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-31 12:38:32 +08:00
|
|
|
|
if (!function_exists('exif_imagetype')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
function exif_imagetype($name): string
|
|
|
|
|
|
{
|
|
|
|
|
|
return get_file_extension($name);
|
|
|
|
|
|
}
|
2020-08-31 12:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-11 15:01:22 +08:00
|
|
|
|
|
|
|
|
|
|
if (!function_exists('logger')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Logger
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function logger(): Logger
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->getLogger();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-09 15:37:23 +08:00
|
|
|
|
|
2021-06-09 15:41:13 +08:00
|
|
|
|
if (!function_exists('trim_blank')) {
|
2021-06-09 15:37:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-09 15:40:23 +08:00
|
|
|
|
* 空白字符替换
|
|
|
|
|
|
* @param string $content 内容
|
|
|
|
|
|
* @param int $len 截取长度
|
|
|
|
|
|
* @param string $encode 编码
|
2021-06-09 15:37:23 +08:00
|
|
|
|
* @param bool $htmlTags
|
2021-06-09 15:40:23 +08:00
|
|
|
|
* @return array|string|null
|
2021-06-09 15:37:23 +08:00
|
|
|
|
*/
|
2021-06-09 15:41:13 +08:00
|
|
|
|
function trim_blank(string $content, $len = 0, $encode = 'utf-8', $htmlTags = true): array|string|null
|
2021-06-09 15:37:23 +08:00
|
|
|
|
{
|
|
|
|
|
|
$str = trim($content);
|
|
|
|
|
|
if ($htmlTags) {
|
|
|
|
|
|
$str = strip_tags($str);
|
|
|
|
|
|
}
|
|
|
|
|
|
$str = preg_replace('/[\n|\r|\t]+/', '', $str);
|
|
|
|
|
|
$str = preg_replace("/(\s|\ \;| |\xc2\xa0)/", '', $str);
|
|
|
|
|
|
if ($len > 0) {
|
|
|
|
|
|
return mb_substr($str, 0, $len, $encode);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return $str;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-31 12:38:32 +08:00
|
|
|
|
if (!function_exists('get_file_extension')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
function get_file_extension($filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
$mime_types = array(
|
|
|
|
|
|
'txt' => 'text/plain',
|
|
|
|
|
|
'htm' => 'text/html',
|
|
|
|
|
|
'html' => 'text/html',
|
|
|
|
|
|
'php' => 'text/html',
|
|
|
|
|
|
'css' => 'text/css',
|
|
|
|
|
|
'js' => 'application/javascript',
|
|
|
|
|
|
'json' => 'application/json',
|
|
|
|
|
|
'xml' => 'application/xml',
|
|
|
|
|
|
'swf' => 'application/x-shockwave-flash',
|
|
|
|
|
|
'flv' => 'video/x-flv',
|
|
|
|
|
|
|
|
|
|
|
|
// images
|
|
|
|
|
|
'png' => 'image/png',
|
|
|
|
|
|
'jpeg' => 'image/jpeg',
|
|
|
|
|
|
'gif' => 'image/gif',
|
|
|
|
|
|
'bmp' => 'image/bmp',
|
|
|
|
|
|
'ico' => 'image/vnd.microsoft.icon',
|
|
|
|
|
|
'tiff' => 'image/tiff',
|
|
|
|
|
|
'svg' => 'image/svg+xml',
|
|
|
|
|
|
|
|
|
|
|
|
// archives
|
|
|
|
|
|
'zip' => 'application/zip',
|
|
|
|
|
|
'rar' => 'application/x-rar-compressed',
|
|
|
|
|
|
'exe' => 'application/x-msdownload',
|
|
|
|
|
|
'msi' => 'application/x-msdownload',
|
|
|
|
|
|
'cab' => 'application/vnd.ms-cab-compressed',
|
|
|
|
|
|
|
|
|
|
|
|
// audio/video
|
|
|
|
|
|
'mp3' => 'audio/mpeg',
|
|
|
|
|
|
'qt' => 'video/quicktime',
|
|
|
|
|
|
'mov' => 'video/quicktime',
|
|
|
|
|
|
|
|
|
|
|
|
// adobe
|
|
|
|
|
|
'pdf' => 'application/pdf',
|
|
|
|
|
|
'psd' => 'image/vnd.adobe.photoshop',
|
|
|
|
|
|
'ai' => 'application/postscript',
|
|
|
|
|
|
'eps' => 'application/postscript',
|
|
|
|
|
|
'ps' => 'application/postscript',
|
|
|
|
|
|
|
|
|
|
|
|
// ms office
|
|
|
|
|
|
'doc' => 'application/msword',
|
|
|
|
|
|
'rtf' => 'application/rtf',
|
|
|
|
|
|
'xls' => 'application/vnd.ms-excel',
|
|
|
|
|
|
'ppt' => 'application/vnd.ms-powerpoint',
|
|
|
|
|
|
|
|
|
|
|
|
// open office
|
|
|
|
|
|
'odt' => 'application/vnd.oasis.opendocument.text',
|
|
|
|
|
|
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$explode = explode('.', $filename);
|
|
|
|
|
|
$ext = strtolower(array_pop($explode));
|
|
|
|
|
|
if (array_key_exists($ext, $mime_types)) {
|
|
|
|
|
|
return $ext;
|
|
|
|
|
|
} elseif (function_exists('finfo_open')) {
|
|
|
|
|
|
$fInfo = finfo_open(FILEINFO_MIME);
|
|
|
|
|
|
$mimeType = finfo_file($fInfo, $filename);
|
|
|
|
|
|
finfo_close($fInfo);
|
|
|
|
|
|
$mimeType = current(explode('; ', $mimeType));
|
|
|
|
|
|
if (($search = array_search($mimeType, $mime_types)) == false) {
|
|
|
|
|
|
return $mimeType;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $search;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 'application/octet-stream';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-31 12:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('request')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Request
|
2021-04-08 15:05:44 +08:00
|
|
|
|
* @throws Exception
|
2021-04-07 14:15:50 +08:00
|
|
|
|
*/
|
|
|
|
|
|
function request(): Request
|
|
|
|
|
|
{
|
2021-05-07 11:10:47 +08:00
|
|
|
|
$request = Context::getContext('request');
|
|
|
|
|
|
if ($request === null) {
|
|
|
|
|
|
$request = make('request', Request::class);
|
|
|
|
|
|
}
|
|
|
|
|
|
return $request;
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2020-08-31 12:38:32 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('Input')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return HttpParams
|
2021-04-08 15:05:44 +08:00
|
|
|
|
* @throws Exception
|
2021-04-07 14:15:50 +08:00
|
|
|
|
*/
|
|
|
|
|
|
function Input(): HttpParams
|
|
|
|
|
|
{
|
|
|
|
|
|
return request()->params;
|
|
|
|
|
|
}
|
2020-08-31 12:38:32 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-28 16:09:18 +08:00
|
|
|
|
if (!function_exists('Server')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Http|Packet|Receive|Websocket|null
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function Server(): Http|Packet|Receive|Websocket|null
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->getSwoole();
|
|
|
|
|
|
}
|
2021-03-28 16:09:18 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
|
if (!function_exists('storage')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param string $fileName
|
|
|
|
|
|
* @param string $path
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function storage($fileName = '', $path = ''): string
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$basePath = rtrim(Snowflake::getStoragePath(), '/');
|
|
|
|
|
|
if (!empty($path)) {
|
|
|
|
|
|
$path = ltrim($path, '/');
|
|
|
|
|
|
if (!is_dir($basePath . '/' . $path)) {
|
|
|
|
|
|
mkdir($basePath . '/' . $path, 0777, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (empty($fileName)) {
|
|
|
|
|
|
return $basePath . '/' . $path . '/';
|
|
|
|
|
|
}
|
|
|
|
|
|
$fileName = $basePath . '/' . $path . '/' . $fileName;
|
|
|
|
|
|
if (!file_exists($fileName)) {
|
|
|
|
|
|
touch($fileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
return $fileName;
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-22 17:44:24 +08:00
|
|
|
|
if (!function_exists('listen')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
* @param $callback
|
|
|
|
|
|
* @param $params
|
|
|
|
|
|
* @param $isAppend
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function listen($name, $callback, $params = [], $isAppend = true)
|
|
|
|
|
|
{
|
2021-04-27 15:57:50 +08:00
|
|
|
|
Event::on($name, $callback, $params, $isAppend);
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2021-02-22 17:44:24 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-04 17:12:41 +08:00
|
|
|
|
if (!function_exists('event')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
* @param $callback
|
|
|
|
|
|
* @param $params
|
|
|
|
|
|
* @param $isAppend
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function event($name, $callback, $params = [], $isAppend = true)
|
|
|
|
|
|
{
|
2021-04-27 15:57:50 +08:00
|
|
|
|
Event::on($name, $callback, $params, $isAppend);
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2021-04-04 17:12:41 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
|
if (!function_exists('alias')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $class
|
|
|
|
|
|
* @param $name
|
|
|
|
|
|
*/
|
|
|
|
|
|
function alias($class, $name)
|
|
|
|
|
|
{
|
|
|
|
|
|
Snowflake::setAlias($class, $name);
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('name')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param int $pid
|
|
|
|
|
|
* @param string|null $prefix
|
|
|
|
|
|
* @throws ConfigException
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function name(int $pid, string $prefix = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Snowflake::getPlatform()->isMac()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-03-09 19:40:10 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$name = Config::get('id', 'system') . '[' . $pid . ']';
|
|
|
|
|
|
if (!empty($prefix)) {
|
|
|
|
|
|
$name .= '.' . $prefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
swoole_set_process_name($name);
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('response')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Response|stdClass
|
|
|
|
|
|
* @throws
|
|
|
|
|
|
*/
|
|
|
|
|
|
function response(): Response|stdClass
|
|
|
|
|
|
{
|
2021-04-27 16:52:44 +08:00
|
|
|
|
return Snowflake::getApp('response');
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 11:44:14 +08:00
|
|
|
|
if (!function_exists('send')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $context
|
2021-07-06 17:36:26 +08:00
|
|
|
|
* @param int $statusCode
|
2021-04-07 14:15:50 +08:00
|
|
|
|
* @return mixed
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
2021-07-06 17:36:26 +08:00
|
|
|
|
function send($context, int $statusCode = 404): mixed
|
2021-04-07 14:15:50 +08:00
|
|
|
|
{
|
2021-07-06 17:36:26 +08:00
|
|
|
|
if (is_array($context)) $context = Json::encode($context);
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
return \response()->send($context, $statusCode);
|
|
|
|
|
|
}
|
2020-09-09 11:44:14 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-21 02:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
if (!function_exists('zero_full')) {
|
2021-04-07 14:15:50 +08:00
|
|
|
|
function zero_full(int $data = 1, int $length = 10): string
|
|
|
|
|
|
{
|
|
|
|
|
|
return sprintf('%0' . $length . 'd', $data);
|
|
|
|
|
|
}
|
2021-03-21 02:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
|
if (!function_exists('redirect')) {
|
|
|
|
|
|
|
2021-01-15 15:53:10 +08:00
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $url
|
|
|
|
|
|
* @return int
|
|
|
|
|
|
*/
|
|
|
|
|
|
function redirect($url): int
|
|
|
|
|
|
{
|
|
|
|
|
|
return response()->redirect($url);
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('env')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $key
|
|
|
|
|
|
* @param null $default
|
|
|
|
|
|
* @return array|string|null
|
|
|
|
|
|
*/
|
|
|
|
|
|
#[Pure] function env($key, $default = null): null|array|string
|
|
|
|
|
|
{
|
|
|
|
|
|
$env = getenv($key);
|
|
|
|
|
|
if ($env === false) {
|
|
|
|
|
|
return $default;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $env;
|
|
|
|
|
|
}
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2020-08-31 01:59:30 +08:00
|
|
|
|
|
|
|
|
|
|
if (!function_exists('sweep')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param string $configPath
|
|
|
|
|
|
* @return array|false|string|null
|
|
|
|
|
|
*/
|
|
|
|
|
|
function sweep($configPath = APP_PATH . 'config'): bool|array|string|null
|
|
|
|
|
|
{
|
|
|
|
|
|
$array = [];
|
|
|
|
|
|
foreach (glob($configPath . '/*') as $config) {
|
2021-05-17 18:33:40 +08:00
|
|
|
|
$array = array_merge(require_once "$config", $array);
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
return $array;
|
|
|
|
|
|
}
|
2021-03-24 17:57:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('swoole_serialize')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $data
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
function swoole_serialize($data): string
|
|
|
|
|
|
{
|
2021-03-26 01:52:36 +08:00
|
|
|
|
// if (class_exists('swoole_serialize')) {
|
|
|
|
|
|
// return \swoole_serialize::pack($data);
|
|
|
|
|
|
// } else {
|
2021-04-07 14:15:50 +08:00
|
|
|
|
return serialize($data);
|
2021-03-26 01:52:36 +08:00
|
|
|
|
// }
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2021-03-24 17:57:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('swoole_unserialize')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $data
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
function swoole_unserialize($data): mixed
|
|
|
|
|
|
{
|
|
|
|
|
|
if (empty($data)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2021-03-26 01:52:36 +08:00
|
|
|
|
// if (class_exists('swoole_serialize')) {
|
|
|
|
|
|
// return \swoole_serialize::unpack($data);
|
|
|
|
|
|
// } else {
|
2021-04-07 14:15:50 +08:00
|
|
|
|
return unserialize($data);
|
2021-03-26 01:52:36 +08:00
|
|
|
|
// }
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
2020-08-31 01:59:30 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2020-09-02 20:07:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('merge')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $param
|
|
|
|
|
|
* @param $param1
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
function merge($param, $param1): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return ArrayAccess::merge($param, $param1);
|
|
|
|
|
|
}
|
2020-09-02 20:07:02 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2020-09-03 18:51:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
2020-10-29 18:17:25 +08:00
|
|
|
|
if (!function_exists('router')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @return Router
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function router(): Router
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->getRouter();
|
|
|
|
|
|
}
|
2020-10-29 18:17:25 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 16:21:18 +08:00
|
|
|
|
if (!function_exists('isService')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param string $name
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
|
|
|
|
|
#[Pure] function isService(string $name): bool
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->has($name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('getService')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param string $name
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getService(string $name): mixed
|
|
|
|
|
|
{
|
|
|
|
|
|
return Snowflake::app()->get($name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-03 18:51:13 +08:00
|
|
|
|
if (!function_exists('jTraceEx')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $e
|
|
|
|
|
|
* @param null $seen
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
|
|
|
|
|
function jTraceEx($e, $seen = null): string
|
|
|
|
|
|
{
|
|
|
|
|
|
$starter = $seen ? 'Caused by: ' : '';
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
if (!$seen) $seen = array();
|
|
|
|
|
|
$trace = $e->getTrace();
|
|
|
|
|
|
$prev = $e->getPrevious();
|
2021-04-25 11:22:23 +08:00
|
|
|
|
$result[] = sprintf('%s%s: %s', $starter, $e::class, $e->getMessage());
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$file = $e->getFile();
|
|
|
|
|
|
$line = $e->getLine();
|
2021-04-28 10:43:16 +08:00
|
|
|
|
|
|
|
|
|
|
foreach ($trace as $value) {
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$result[] = sprintf(' at %s%s%s(%s%s%s)',
|
2021-04-28 10:43:16 +08:00
|
|
|
|
count($value) && array_key_exists('class', $value) ? str_replace('\\', '.', $value['class']) : '',
|
|
|
|
|
|
count($value) && array_key_exists('class', $value) && array_key_exists('function', $value) ? '.' : '',
|
|
|
|
|
|
count($value) && array_key_exists('function', $value) ? str_replace('\\', '.', $value['function']) : '(main)',
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$line === null ? $file : basename($file),
|
|
|
|
|
|
$line === null ? '' : ':',
|
|
|
|
|
|
$line === null ? '' : $line);
|
2021-04-28 10:43:16 +08:00
|
|
|
|
|
|
|
|
|
|
$file = array_key_exists('file', $value) ? $value['file'] : 'Unknown Source';
|
|
|
|
|
|
$line = array_key_exists('file', $value) && array_key_exists('line', $value) && $value['line'] ? $value['line'] : null;
|
2021-04-07 14:15:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
$result = join("\n", $result);
|
2021-04-28 10:43:16 +08:00
|
|
|
|
if ($prev) {
|
2021-04-07 14:15:50 +08:00
|
|
|
|
$result .= "\n" . jTraceEx($prev, $seen);
|
2021-04-28 10:43:16 +08:00
|
|
|
|
}
|
2021-04-07 14:15:50 +08:00
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
2020-09-03 18:51:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-11-04 19:28:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('swoole_substr_json_decode')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $packet
|
|
|
|
|
|
* @param int $length
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
*/
|
|
|
|
|
|
function swoole_substr_json_decode($packet, $length = 0): mixed
|
|
|
|
|
|
{
|
|
|
|
|
|
return json_decode($packet, true);
|
|
|
|
|
|
}
|
2020-11-04 19:28:40 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('swoole_substr_unserialize')) {
|
|
|
|
|
|
|
2021-04-07 14:15:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $packet
|
|
|
|
|
|
* @param int $length
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
*/
|
|
|
|
|
|
function swoole_substr_unserialize($packet, $length = 0): mixed
|
|
|
|
|
|
{
|
|
|
|
|
|
return unserialize($packet);
|
|
|
|
|
|
}
|
2020-11-04 19:28:40 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2021-05-08 16:28:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('debug')) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param $message
|
|
|
|
|
|
* @param string $method
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function debug(mixed $message, string $method = 'app')
|
|
|
|
|
|
{
|
|
|
|
|
|
Snowflake::app()->debug($message, $method);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('error')) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param $message
|
|
|
|
|
|
* @param string $method
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function error(mixed $message, $method = 'error')
|
|
|
|
|
|
{
|
|
|
|
|
|
Snowflake::app()->error($message, $method);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!function_exists('success')) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param $message
|
|
|
|
|
|
* @param string $method
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
function success(mixed $message, $method = 'app')
|
|
|
|
|
|
{
|
|
|
|
|
|
Snowflake::app()->success($message, $method);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|