File tree Expand file tree Collapse file tree 6 files changed +89
-4
lines changed
Expand file tree Collapse file tree 6 files changed +89
-4
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,6 @@ protected function process()
4646 $ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
4747 ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
4848
49- return $ result ?: [];
49+ return $ event -> result ?: [];
5050 }
5151}
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ protected function process()
3333 ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
3434
3535 return [
36- 'count ' => $ count
36+ 'count ' => $ event -> result
3737 ];
3838 }
3939}
Original file line number Diff line number Diff line change @@ -33,6 +33,6 @@ protected function process()
3333 $ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
3434 ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
3535
36- return $ result ;
36+ return $ event -> result ;
3737 }
3838}
Original file line number Diff line number Diff line change @@ -49,6 +49,6 @@ protected function process()
4949 $ event = new QueryExecuteAfter ($ this ->query ->toSql (), $ this ->method , $ result );
5050 ApplicationContext::getContainer ()->get (EventDispatcherInterface::class)->dispatch ($ event );
5151
52- return $ result ;
52+ return $ event -> result ;
5353 }
5454}
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()
325325 ],
326326 ], $ result );
327327 }
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+ }
328370}
You can’t perform that action at this time.
0 commit comments