File tree 6 files changed +89
-4
lines changed
6 files changed +89
-4
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,6 @@ protected function process()
46
46
$ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
47
47
ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
48
48
49
- return $ result ?: [];
49
+ return $ event -> result ?: [];
50
50
}
51
51
}
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ protected function process()
33
33
ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
34
34
35
35
return [
36
- 'count ' => $ count
36
+ 'count ' => $ event -> result
37
37
];
38
38
}
39
39
}
Original file line number Diff line number Diff line change @@ -33,6 +33,6 @@ protected function process()
33
33
$ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
34
34
ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
35
35
36
- return $ result ;
36
+ return $ event -> result ;
37
37
}
38
38
}
Original file line number Diff line number Diff line change @@ -49,6 +49,6 @@ protected function process()
49
49
$ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
50
50
ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
51
51
52
- return $ result ;
52
+ return $ event -> result ;
53
53
}
54
54
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace App \Listener ;
5
+
6
+ use App \Event \ApiJson \QueryExecuteAfter ;
7
+ use Hyperf \Event \Annotation \Listener ;
8
+ use Hyperf \Event \Contract \ListenerInterface ;
9
+
10
+ /**
11
+ * @Listener
12
+ */
13
+ class QueryResultTryToJsonListener implements ListenerInterface
14
+ {
15
+ public function listen (): array
16
+ {
17
+ return [
18
+ QueryExecuteAfter::class,
19
+ ];
20
+ }
21
+
22
+ public function process (object $ event )
23
+ {
24
+ if (!$ event instanceof QueryExecuteAfter) return ;
25
+ if ($ event ->method != 'GET ' ) return ;
26
+ $ event ->result = $ this ->toJson ($ event ->result );
27
+ }
28
+
29
+ private function toJson (array $ result ): array
30
+ {
31
+ foreach ($ result as $ key => $ value ) {
32
+ if (is_array ($ value )) {
33
+ $ result [$ key ] = $ this ->toJson ($ value );
34
+ }
35
+ if (!is_string ($ value )) continue ;
36
+ $ jsonData = json_decode ($ value , true );
37
+ if (is_array ($ jsonData )) {
38
+ $ result [$ key ] = $ jsonData ;
39
+ }
40
+ }
41
+ return $ result ;
42
+ }
43
+ }
Original file line number Diff line number Diff line change @@ -325,4 +325,46 @@ public function testWhereExistsUseSubQuery()
325
325
],
326
326
], $ result );
327
327
}
328
+
329
+ public function testWhereIdSubQuery ()
330
+ {
331
+ $ json = [
332
+ "User " => [
333
+ "id@ " => [
334
+ "from " =>"Comment " ,
335
+ "Comment " => [
336
+ "@column " =>"min(userId) "
337
+ ]
338
+ ]
339
+ ]
340
+ ];
341
+ $ parse = new Parse ($ json , $ this ->method , '' );
342
+ $ result = $ parse ->handle ();
343
+
344
+ $ this ->assertSame ([
345
+ "User " => [
346
+ "id " =>38710 ,
347
+ "sex " =>0 ,
348
+ "name " =>"TommyLemon " ,
349
+ "tag " =>"Android&Java " ,
350
+ "head " =>"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000 " ,
351
+ "contactIdList " =>[
352
+ 82003 ,
353
+ 82005 ,
354
+ 90814 ,
355
+ 82004 ,
356
+ 82009 ,
357
+ 82002 ,
358
+ 82044 ,
359
+ 93793 ,
360
+ 70793
361
+ ],
362
+ "pictureList " =>[
363
+ "http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000 " ,
364
+ "http://common.cnblogs.com/images/icon_weibo_24.png "
365
+ ],
366
+ "date " =>"2017-02-01 11:21:50 "
367
+ ]
368
+ ], $ result );
369
+ }
328
370
}
You can’t perform that action at this time.
0 commit comments