File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 8
8
use Cake \Datasource \QueryTrait ;
9
9
use Cake \Utility \Hash ;
10
10
use IteratorAggregate ;
11
+ use JsonSerializable ;
11
12
use Muffin \Webservice \Model \Endpoint ;
12
13
use Muffin \Webservice \Webservice \WebserviceInterface ;
13
14
14
- class Query implements QueryInterface, IteratorAggregate
15
+ class Query implements IteratorAggregate, JsonSerializable, QueryInterface
15
16
{
16
17
17
18
use QueryTrait;
@@ -520,4 +521,16 @@ public function __debugInfo()
520
521
'webservice ' => $ this ->webservice ()
521
522
];
522
523
}
524
+
525
+ /**
526
+ * Executes the query and converts the result set into JSON.
527
+ *
528
+ * Part of JsonSerializable interface.
529
+ *
530
+ * @return \Cake\Datasource\ResultSetInterface The data to convert to JSON.
531
+ */
532
+ public function jsonSerialize ()
533
+ {
534
+ return $ this ->all ();
535
+ }
523
536
}
Original file line number Diff line number Diff line change @@ -212,6 +212,17 @@ public function testDebugInfo()
212
212
], $ this ->query ->__debugInfo ());
213
213
}
214
214
215
+ public function testJsonSerialize ()
216
+ {
217
+ $ expected = [
218
+ ['id ' => 1 , 'title ' => 'Hello World ' ],
219
+ ['id ' => 2 , 'title ' => 'New ORM ' ],
220
+ ['id ' => 3 , 'title ' => 'Webservices ' ]
221
+ ];
222
+
223
+ $ this ->assertEquals (json_encode ($ expected ), json_encode ($ this ->query ));
224
+ }
225
+
215
226
/**
216
227
* @inheritDoc
217
228
*/
You can’t perform that action at this time.
0 commit comments