first commit

This commit is contained in:
wushumin
2026-04-16 11:17:18 +08:00
commit 5b9c398e68
98 changed files with 8701 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace support;
use Throwable;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\Exception\ExceptionHandler as BaseExceptionHandler;
use app\common\exception\BusinessException;
class ExceptionHandler extends BaseExceptionHandler
{
public function render(Request $request, Throwable $exception): Response
{
$code = $exception->getCode();
$message = $exception->getMessage();
$data = null;
if ($exception instanceof BusinessException) {
$code = $code ?: 400;
$data = $exception->getData();
} else {
$code = 500;
$message = 'Server internal error';
if (config('app.debug')) {
$message = $exception->getMessage();
}
}
return json([
'code' => $code,
'msg' => $message,
'data' => $data,
]);
}
}

24
support/Request.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace support;
/**
* Class Request
* @package support
*/
class Request extends \Webman\Http\Request
{
}

24
support/Response.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace support;
/**
* Class Response
* @package support
*/
class Response extends \Webman\Http\Response
{
}

1558
support/Setup.php Normal file

File diff suppressed because it is too large Load Diff

3
support/bootstrap.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
require_once __DIR__ . '/../vendor/workerman/webman-framework/src/support/bootstrap.php';

View File

@@ -0,0 +1,20 @@
<?php
namespace support\bootstrap;
use Illuminate\Database\Capsule\Manager as Capsule;
class Database
{
public static function start($worker)
{
$config = config('database');
$default = $config['default'] ?? 'mysql';
$connection = $config['connections'][$default] ?? [];
$capsule = new Capsule();
$capsule->addConnection($connection);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
}

25
support/helpers.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
if (!function_exists('jsonResponse')) {
function jsonResponse($data = [], $msg = 'success', $code = 200)
{
return json([
'code' => $code,
'msg' => $msg,
'data' => $data
]);
}
}
if (!function_exists('generateToken')) {
function generateToken(): string
{
return bin2hex(random_bytes(32));
}
}
if (!function_exists('hashToken')) {
function hashToken(string $token): string
{
return hash('sha256', $token);
}
}