We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config/soar.php
<?php declare(strict_types=1); /** * This file is part of project hyperf-soar. * * @author [email protected] * @link https://github.com/wilbur-yu * * @link https://www.hyperf.io * @document https://hyperf.wiki * @contact [email protected] * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ 'enabled' => env('SOAR_ENABLED', env('APP_ENV') === 'local'), 'cut_classes' => [ 'Hyperf\HttpServer\Response::json', ], '-soar-path' => env('SOAR_PATH', ''), // soar 二进制文件的绝对路径 '-test-dsn' => [ 'host' => env('SOAR_TEST_DSN_HOST', '127.0.0.1'), 'port' => env('SOAR_TEST_DSN_PORT', '3306'), 'dbname' => env('SOAR_TEST_DSN_DBNAME', 'database'), 'username' => env('SOAR_TEST_DSN_USER', 'root'), 'password' => env('SOAR_TEST_DSN_PASSWORD', ''), 'disable' => env('SOAR_TEST_DSN_DISABLE', false), ], '-sampling' => env('SOAR_SAMPLING', true), // 是否开启数据采样开关 '-allow-drop-index' => env('SOAR_ALLOW_DROP_INDEX', true), // 允许输出删除重复索引的建议 '-drop-test-temporary' => env('SOAR_DROP_TEST_TEMPORARY', true), // 是否清理测试环境产生的临时库表 '-log-output' => BASE_PATH.'/runtime/logs/soar.log', ];
.env
# soar SOAR_ENABLED=true SOAR_TEST_DSN_DISABLE=false SOAR_PATH=soar_alpine_docker SOAR_TEST_DSN_HOST=mysql SOAR_TEST_DSN_PORT=3306 SOAR_TEST_DSN_DBNAME=tisu_pd SOAR_TEST_DSN_USER=root SOAR_TEST_DSN_PASSWORD=123456 SOAR_REPORT_TYPE=json
说明:我的二进制文件在docker内,且在/usr/local/bin下,已赋予777权限
业务成功返回是调用的是 response的json
<?php /** * Created by PhpStorm. * * ReqResponse.php * * User:YM * Date:2019/11/15 * Time:下午5:35 */ namespace Core\Common\Container; use App\Constants\StatusCode; use Core\Common\Facade\Log; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Cookie\Cookie; use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\ResponseInterface; use Hyperf\Utils\Context; use Hyperf\Utils\Str; use Psr\Http\Message\ResponseInterface as PsrResponseInterface; use Swoole\Coroutine; /** * ReqResponse * 请求响应结果 * @package Core\Common\Container * User:YM * Date:2019/11/15 * Time:下午5:35 */ class Response { /** * @Inject * @var RequestInterface */ protected $request; /** * @Inject * @var ResponseInterface */ protected $response; /** * success * 成功返回请求结果 * User:YM * Date:2019/11/19 * Time:上午11:04 * @param array $data * @param string|null $msg * @return \Psr\Http\Message\ResponseInterface */ public function success($data = [], string $msg = null) { $msg = $msg ?? StatusCode::getMessage(StatusCode::SUCCESS);; $data = [ // 'qid' => $this->request->getHeaderLine('qid'), 'code' => StatusCode::SUCCESS, 'msg' => $msg, 'data' => $data ]; $response = $this->response->json($data); $executionTime = microtime(true) - Context::get('request_start_time'); $rbs = strlen($response->getBody()->getContents()); //排除的接口 $uri = $this->request->getRequestTarget(); $needExclude = Str::startsWith((string)$uri, ['/admin_api/sys_log/list']); if (!$needExclude) { // 获取日志实例,记录日志 $logger = Log::get(requestEntry(Coroutine::getBackTrace())); $logger->info($msg, getLogArguments($executionTime, $rbs)); } return $response; } /** * error * 业务相关错误结果返回 * User:YM * Date:2019/11/20 * Time:上午10:04 * @param int $code * @param string|null $msg * @return \Psr\Http\Message\ResponseInterface */ public function error(int $code = StatusCode::ERR_EXCEPTION, string $msg = null) { $msg = $msg ?? StatusCode::getMessage($code);; $data = [ 'qid' => $this->request->getHeaderLine('qid'), 'code' => $code, 'msg' => $msg, ]; return $this->response->json($data); } /** * @param string|null $msg * @param int $code * @return PsrResponseInterface */ public function failed(string $msg = '', int $code = StatusCode::ERR_EXCEPTION) { $msg = $msg ?? StatusCode::getMessage($code);; $data = [ 'qid' => $this->request->getHeaderLine('qid'), 'code' => $code, 'msg' => $msg, ]; return $this->response->json($data); } /** * json * 直接返回数据 * User:YM * Date:2019/12/16 * Time:下午4:22 * @param $data * @return \Psr\Http\Message\ResponseInterface */ public function json(array $data) { return $this->response->json($data); } /** * xml * 返回xml数据 * User:YM * Date:2019/12/16 * Time:下午4:58 * @param $data * @return \Psr\Http\Message\ResponseInterface */ public function xml(array $data) { return $this->response->xml($data); } /** * redirect * 重定向 * User:YM * Date:2019/12/16 * Time:下午5:00 * @param string $url * @param string $schema * @param int $status * @return \Psr\Http\Message\ResponseInterface */ public function redirect(string $url, string $schema = 'http', int $status = 302) { return $this->response->redirect($url, $status, $schema); } /** * download * 下载文件 * User:YM * Date:2019/12/16 * Time:下午5:04 * @param string $file * @param string $name * @return \Psr\Http\Message\ResponseInterface */ public function download(string $file, string $name = '') { return $this->response->download($file, $name); } public function raw($data) { return $this->response->raw($data); } /** * cookie * 设置cookie * User:YM * Date:2019/12/16 * Time:下午10:17 * @param string $name * @param string $value * @param int $expire * @param string $path * @param string $domain * @param bool $secure * @param bool $httpOnly * @param bool $raw * @param null|string $sameSite */ public function cookie(string $name, string $value = '', $expire = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = true, bool $raw = false, ?string $sameSite = null) { // convert expiration time to a Unix timestamp if ($expire instanceof \DateTimeInterface) { $expire = $expire->format('U'); } elseif (!is_numeric($expire)) { $expire = strtotime($expire); if ($expire === false) { throw new \RuntimeException('The cookie expiration time is not valid.'); } } $cookie = new Cookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $raw, $sameSite); $response = $this->response->withCookie($cookie); Context::set(PsrResponseInterface::class, $response); return; } /** * @return ResponseInterface */ public function getResponse(): ResponseInterface { return $this->response; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
config/soar.php
.env
说明:我的二进制文件在docker内,且在/usr/local/bin下,已赋予777权限
业务成功返回是调用的是 response的json
The text was updated successfully, but these errors were encountered: