File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ public static function getDb()
9999 public static function modelName ()
100100 {
101101 $ path = Inflector::camel2id (StringHelper::basename (get_called_class ()), '- ' );
102- return self ::getDb ()->usePluralisation ? Inflector::pluralize ($ path ) : $ path ;
102+ return static ::getDb ()->usePluralisation ? Inflector::pluralize ($ path ) : $ path ;
103103 }
104104
105105
Original file line number Diff line number Diff line change @@ -170,6 +170,10 @@ protected function queryInternal($method = 'get')
170170 if ($ this ->db ->usePluralisation && strpos ($ this ->pathInfo , '/ ' ) === false ) {
171171 $ this ->pathInfo = Inflector::pluralize ($ this ->pathInfo );
172172 }
173+ if (!$ this ->db ->useFilterKeyword ) {
174+ $ filter = ArrayHelper::remove ($ this ->queryParams , 'filter ' , []);
175+ $ this ->queryParams = array_merge ($ this ->queryParams , $ filter );
176+ }
173177
174178 return $ this ->db ->$ method ($ this ->pathInfo , $ this ->queryParams );
175179 }
Original file line number Diff line number Diff line change @@ -57,9 +57,13 @@ class Connection extends Component
5757 */
5858 public $ responseConfig = [];
5959 /**
60- * @var boolean Whether to user pluralisation or not
60+ * @var boolean Whether to use pluralisation or not
6161 */
6262 public $ usePluralisation = true ;
63+ /**
64+ * @var boolean Whether to use filter keyword or not
65+ */
66+ public $ useFilterKeyword = true ;
6367 /**
6468 * @var boolean Whether the connection should throw an exception if response is not 200 or not
6569 */
Original file line number Diff line number Diff line change @@ -40,6 +40,34 @@ public function testGetAnotherOne()
4040 $ this ->assertStringStartsWith ('https://api.site.com/rest-models/1 ' , $ logEntry ['url ' ]);
4141 }
4242
43+ public function testFilter ()
44+ {
45+ RestModel::find ()->where (['name ' => 'John ' ])->one ();
46+
47+ $ logEntry = $ this ->parseLogs ();
48+
49+ $ this ->assertEquals ('GET ' , $ logEntry ['method ' ]);
50+ $ this ->assertStringStartsWith ('https://api.site.com/rest-models?filter%5Bname%5D=John ' , $ logEntry ['url ' ]);
51+ }
52+
53+ public function testWithoutFilterKeyword ()
54+ {
55+ $ this ->mockWebApplication ([
56+ 'components ' => [
57+ 'rest ' => [
58+ 'useFilterKeyword ' => false
59+ ]
60+ ]
61+ ]);
62+
63+ RestModel::find ()->where (['name ' => 'John ' ])->one ();
64+
65+ $ logEntry = $ this ->parseLogs ();
66+
67+ $ this ->assertEquals ('GET ' , $ logEntry ['method ' ]);
68+ $ this ->assertStringStartsWith ('https://api.site.com/rest-models?name=John ' , $ logEntry ['url ' ]);
69+ }
70+
4371 public function testDeleteOne ()
4472 {
4573 $ model = new RestModel ([
You can’t perform that action at this time.
0 commit comments