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