-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[新增功能](master):V1.1.0 发布
- Loading branch information
Showing
869 changed files
with
22,972 additions
and
9,808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
api-server/app/core/common/src/Exception/CommonException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MoChat. | ||
* @link https://mo.chat | ||
* @document https://mochat.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE | ||
*/ | ||
namespace MoChat\App\Common\Exception; | ||
|
||
use Hyperf\Server\Exception\ServerException; | ||
use MoChat\App\Common\Constants\AppErrCode; | ||
|
||
class CommonException extends ServerException | ||
{ | ||
public function __construct(int $code = 0, string $message = null, \Throwable $previous = null) | ||
{ | ||
if (is_null($message)) { | ||
$message = AppErrCode::getMessage($code); | ||
if (! $message && class_exists(AppErrCode::class)) { | ||
$message = AppErrCode::getMessage($code); | ||
} | ||
} | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
api-server/app/core/common/src/Exception/Handler/CommonExceptionHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MoChat. | ||
* @link https://mo.chat | ||
* @document https://mochat.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE | ||
*/ | ||
namespace MoChat\App\Common\Exception\Handler; | ||
|
||
use Hyperf\Contract\StdoutLoggerInterface; | ||
use Hyperf\ExceptionHandler\ExceptionHandler; | ||
use Hyperf\HttpMessage\Stream\SwooleStream; | ||
use MoChat\App\Common\Constants\AppErrCode; | ||
use MoChat\App\Common\Exception\CommonException; | ||
use MoChat\Framework\Constants\ErrorCode; | ||
use Throwable; | ||
|
||
/** | ||
* 常规错误信息返回. | ||
*/ | ||
class CommonExceptionHandler extends ExceptionHandler | ||
{ | ||
/** | ||
* @var StdoutLoggerInterface | ||
*/ | ||
protected $logger; | ||
|
||
public function __construct(StdoutLoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function handle(Throwable $throwable, \Psr\Http\Message\ResponseInterface $response) | ||
{ | ||
## 记录日志 | ||
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); | ||
$this->logger->error($throwable->getTraceAsString()); | ||
|
||
## 格式化输出 | ||
$data = responseDataFormat($throwable->getCode(), $throwable->getMessage()); | ||
$httpCode = ErrorCode::getHttpCode($data['code']); | ||
if (! $httpCode && class_exists(AppErrCode::class)) { | ||
$httpCode = AppErrCode::getHttpCode($data['code']); | ||
} | ||
$dataStream = new SwooleStream(json_encode($data, JSON_UNESCAPED_UNICODE)); | ||
|
||
## 阻止异常冒泡 | ||
$this->stopPropagation(); | ||
return $response->withHeader('Server', 'mochat') | ||
->withAddedHeader('Content-Type', 'application/json;charset=utf-8') | ||
->withStatus($httpCode) | ||
->withBody($dataStream); | ||
} | ||
|
||
public function isValid(Throwable $throwable): bool | ||
{ | ||
return $throwable instanceof CommonException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
* @contact [email protected] | ||
* @license https://github.com/mochat-cloud/mochat/blob/master/LICENSE | ||
*/ | ||
|
||
namespace MoChat\App\Common\Listener; | ||
|
||
use Hyperf\Database\Events\QueryExecuted; | ||
|
@@ -49,7 +48,7 @@ public function process(object $event) | |
{ | ||
if ($event instanceof QueryExecuted) { | ||
$sql = $event->sql; | ||
if (!Arr::isAssoc($event->bindings)) { | ||
if (! Arr::isAssoc($event->bindings)) { | ||
foreach ($event->bindings as $key => $value) { | ||
$sql = Str::replaceFirst('?', "'{$value}'", $sql); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.