@@ -20,10 +20,7 @@ public function __construct(QueryRepository $query) {
2020 */
2121 public function where () {
2222 $ limit = \LockerRequest::getParam ('limit ' , 100 );
23- $ filters = json_decode (
24- \LockerRequest::getParam ('filters ' ),
25- true
26- ) ?: [];
23+ $ filters = $ this ->getParam ('filters ' );
2724 return \Response::json ($ this ->query ->where ($ this ->lrs ->_id , $ filters )->paginate ($ limit ));
2825 }
2926
@@ -32,10 +29,7 @@ public function where() {
3229 * @return Aggregate http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples
3330 */
3431 public function aggregate () {
35- $ pipeline = json_decode (
36- \LockerRequest::getParam ('pipeline ' ),
37- true
38- ) ?: [['$match ' => ['active ' => true ]]];
32+ $ pipeline = $ this ->getParam ('pipeline ' );
3933 return \Response::json ($ this ->query ->aggregate ($ this ->lrs ->_id , $ pipeline ));
4034 }
4135
@@ -44,10 +38,7 @@ public function aggregate() {
4438 * @return Aggregate http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples
4539 */
4640 public function aggregateTime () {
47- $ match = json_decode (
48- \LockerRequest::getParam ('match ' ),
49- true
50- ) ?: [];
41+ $ match = $ this ->getParam ('match ' );
5142 return \Response::json ($ this ->query ->aggregateTime ($ this ->lrs ->_id , $ match ));
5243 }
5344
@@ -56,10 +47,7 @@ public function aggregateTime() {
5647 * @return Aggregate http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples
5748 */
5849 public function aggregateObject () {
59- $ match = json_decode (
60- \LockerRequest::getParam ('match ' ),
61- true
62- ) ?: [];
50+ $ match = $ this ->getParam ('match ' );
6351 return \Response::json ($ this ->query ->aggregateObject ($ this ->lrs ->_id , $ match ));
6452 }
6553
@@ -81,10 +69,15 @@ public function index(){
8169 }
8270
8371 public function void () {
84- $ match = json_decode (
85- \LockerRequest::getParam ('match ' ),
86- true
87- ) ?: [];
72+ $ match = $ this ->getParam ('match ' );
8873 return \Response::json ($ this ->query ->void ($ match , $ this ->getOptions ()));
8974 }
75+
76+ private function getParam ($ param ) {
77+ $ value = json_decode (\LockerRequest::getParam ($ param ), true );
78+ if ($ value === null ) {
79+ throw new Exceptions \Exception ("Expected ` $ param` to be defined as a URL parameter. " );
80+ }
81+ return $ value ;
82+ }
9083}
0 commit comments