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 88use Cake \Datasource \QueryTrait ;
99use Cake \Utility \Hash ;
1010use IteratorAggregate ;
11+ use JsonSerializable ;
1112use Muffin \Webservice \Model \Endpoint ;
1213use Muffin \Webservice \Webservice \WebserviceInterface ;
1314
14- class Query implements QueryInterface, IteratorAggregate
15+ class Query implements IteratorAggregate, JsonSerializable, QueryInterface
1516{
1617
1718 use QueryTrait;
@@ -520,4 +521,16 @@ public function __debugInfo()
520521 'webservice ' => $ this ->webservice ()
521522 ];
522523 }
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+ }
523536}
Original file line number Diff line number Diff line change @@ -212,6 +212,17 @@ public function testDebugInfo()
212212 ], $ this ->query ->__debugInfo ());
213213 }
214214
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+
215226 /**
216227 * @inheritDoc
217228 */
You can’t perform that action at this time.
0 commit comments