Skip to content

Commit 1e1d655

Browse files
committed
去掉helper依赖
1 parent 0e7a1d9 commit 1e1d655

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Middleware/LogsMiddleware.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@
1414

1515
use HPlus\Admin\Facades\Admin;
1616
use HPlus\Admin\Model\Admin\OperationLog;
17-
use HPlus\Helper\RunTime;
1817
use Hyperf\Contract\ConfigInterface;
1918
use Hyperf\Utils\Str;
2019
use Psr\Http\Message\ResponseInterface;
2120
use Psr\Http\Message\ServerRequestInterface;
2221
use Psr\Http\Server\MiddlewareInterface;
2322
use Psr\Http\Server\RequestHandlerInterface;
24-
use Qbhy\HyperfAuth\Authenticatable;
25-
use Qbhy\HyperfAuth\AuthGuard;
2623
use Qbhy\HyperfAuth\AuthManager;
27-
use Qbhy\HyperfAuth\Exception\UnauthorizedException;
2824

2925
/**
3026
* Class AuthMiddleware.
@@ -33,7 +29,7 @@ class LogsMiddleware implements MiddlewareInterface
3329
{
3430
protected $config;
3531

36-
public function __construct(AuthManager $auth, ConfigInterface $config)
32+
public function __construct(ConfigInterface $config)
3733
{
3834
$this->config = $config->get('admin.operation_log');
3935
}
@@ -46,9 +42,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4642
) {
4743
return $handler->handle($request);
4844
}
49-
$RunTime = new RunTime;
45+
$time = $this->getMicroTime();
5046
$response = $handler->handle($request);
51-
$time = $RunTime->spent();
47+
$time = round(($this->getMicroTime() - $time) * 1000, 1);
5248
try {
5349
OperationLog::create([
5450
'user_id' => Admin::user()->getId(),
@@ -62,11 +58,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6258
]);
6359
} catch (\Throwable $exception) {
6460
// pass
65-
Logger()->info("可能您的log日志表不是最新的, 请执行 php bin/hyperf.php admin:db -l 查看升级命令");
61+
Logger()->info("可能您的log日志表不是最新的, 请执行 php bin/hyperf.php admin:db -l 查看升级命令");
6662
}
6763
return $response;
6864
}
6965

66+
private function getMicroTime()
67+
{
68+
list($usec, $sec) = explode(' ', microtime());
69+
return ((float)$usec + (float)$sec);
70+
}
71+
7072
/**
7173
* Whether requests using this method are allowed to be logged.
7274
*

0 commit comments

Comments
 (0)