first commit
This commit is contained in:
35
support/ExceptionHandler.php
Normal file
35
support/ExceptionHandler.php
Normal 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
24
support/Request.php
Normal 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
24
support/Response.php
Normal 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
1558
support/Setup.php
Normal file
File diff suppressed because it is too large
Load Diff
3
support/bootstrap.php
Normal file
3
support/bootstrap.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/workerman/webman-framework/src/support/bootstrap.php';
|
||||
20
support/bootstrap/Database.php
Normal file
20
support/bootstrap/Database.php
Normal 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
25
support/helpers.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user