2
2
3
3
declare (strict_types=1 );
4
4
/**
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.
14
7
*/
15
-
16
8
namespace Wilbur \HyperfSoar \Listener ;
17
9
18
10
use Hyperf \Contract \ConfigInterface ;
23
15
use Hyperf \Utils \Context ;
24
16
use Hyperf \Utils \Str ;
25
17
26
-
27
18
#[Listener]
28
19
class QueryExecListener implements ListenerInterface
29
20
{
30
- protected bool $ soarIsEnabled ;
31
21
public const SQL_RECORD_KEY = 'wilbur-yu-hyperf-soar-sql-listener ' ;
32
22
23
+ protected bool $ soarIsEnabled ;
24
+
33
25
public function __construct (ConfigInterface $ config )
34
26
{
35
- $ this ->soarIsEnabled = $ config ->get ('soar.enabled ' );
27
+ $ this ->soarIsEnabled = $ config ->get ('soar.enabled ' , false );
36
28
}
37
29
38
30
public function listen (): array
@@ -46,12 +38,12 @@ public function process(object $event): void
46
38
{
47
39
if ($ event instanceof QueryExecuted && $ this ->soarIsEnabled ) {
48
40
$ sql = str_replace ('` ' , '' , $ event ->sql );
49
- if (!Arr::isAssoc ($ event ->bindings )) {
41
+ if (! Arr::isAssoc ($ event ->bindings )) {
50
42
foreach ($ event ->bindings as $ value ) {
51
- $ sql = Str::replaceFirst ('? ' , "' $ value' " , $ sql );
43
+ $ sql = Str::replaceFirst ('? ' , "' { $ value} ' " , $ sql );
52
44
}
53
45
}
54
- $ eventSqlList = (array )Context::get (self ::SQL_RECORD_KEY );
46
+ $ eventSqlList = (array ) Context::get (self ::SQL_RECORD_KEY );
55
47
$ eventSqlList [] = $ sql ;
56
48
Context::set (self ::SQL_RECORD_KEY , $ eventSqlList );
57
49
}
0 commit comments