Skip to content

Commit cecb207

Browse files
committed
fixed QueryExecListener
1 parent aee87ef commit cecb207

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/Listener/QueryExecListener.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of project hyperf-soar.
6-
*
7-
* @author wenber.yu@creative-life.club
8-
* @link https://github.com/wilbur-yu
9-
*
10-
* @link https://www.hyperf.io
11-
* @document https://hyperf.wiki
12-
* @contact group@hyperf.io
13-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
5+
* 本文件属于KK馆版权所有,泄漏必究。
6+
* This file belong to KKGUAN, all rights reserved.
147
*/
15-
168
namespace Wilbur\HyperfSoar\Listener;
179

1810
use Hyperf\Contract\ConfigInterface;
@@ -23,16 +15,16 @@
2315
use Hyperf\Utils\Context;
2416
use Hyperf\Utils\Str;
2517

26-
2718
#[Listener]
2819
class QueryExecListener implements ListenerInterface
2920
{
30-
protected bool $soarIsEnabled;
3121
public const SQL_RECORD_KEY = 'wilbur-yu-hyperf-soar-sql-listener';
3222

23+
protected bool $soarIsEnabled;
24+
3325
public function __construct(ConfigInterface $config)
3426
{
35-
$this->soarIsEnabled = $config->get('soar.enabled');
27+
$this->soarIsEnabled = $config->get('soar.enabled', false);
3628
}
3729

3830
public function listen(): array
@@ -46,12 +38,12 @@ public function process(object $event): void
4638
{
4739
if ($event instanceof QueryExecuted && $this->soarIsEnabled) {
4840
$sql = str_replace('`', '', $event->sql);
49-
if (!Arr::isAssoc($event->bindings)) {
41+
if (! Arr::isAssoc($event->bindings)) {
5042
foreach ($event->bindings as $value) {
51-
$sql = Str::replaceFirst('?', "'$value'", $sql);
43+
$sql = Str::replaceFirst('?', "'{$value}'", $sql);
5244
}
5345
}
54-
$eventSqlList = (array)Context::get(self::SQL_RECORD_KEY);
46+
$eventSqlList = (array) Context::get(self::SQL_RECORD_KEY);
5547
$eventSqlList[] = $sql;
5648
Context::set(self::SQL_RECORD_KEY, $eventSqlList);
5749
}

0 commit comments

Comments
 (0)