1 | <?php |
||
12 | abstract class CRUDController extends JSONController |
||
13 | { |
||
14 | /** |
||
15 | * Make sure that the data of a form is valid, only called when creating a |
||
16 | * new object |
||
17 | * @param Form $form The submitted form |
||
18 | * @return void |
||
19 | */ |
||
20 | 1 | protected function validateNew($form) |
|
23 | |||
24 | /** |
||
25 | * Make sure that the data of a form is valid, only called when editing an |
||
26 | * existing object |
||
27 | * @param Form $form The submitted form |
||
28 | * @param PermissionModel $model The model being edited |
||
29 | * @return void |
||
30 | */ |
||
31 | protected function validateEdit($form, $model) |
||
34 | |||
35 | /** |
||
36 | * Make sure that the data of a form is valid |
||
37 | * @param Form $form The submitted form |
||
38 | * @return void |
||
39 | */ |
||
40 | protected function validate($form) |
||
43 | 1 | ||
44 | /** |
||
45 | * Delete a model |
||
46 | * @param PermissionModel $model The model we want to delete |
||
47 | * @param Player $me The user who wants to delete the model |
||
48 | * @param Closure|null $onSuccess Something to do when the model is deleted |
||
49 | 1 | * @throws ForbiddenException |
|
50 | 1 | * @return mixed The response to show to the user |
|
51 | 1 | */ |
|
52 | protected function delete(PermissionModel $model, Player $me, $onSuccess = null) |
||
89 | |||
90 | 1 | /** |
|
91 | * Create a model |
||
92 | 1 | * |
|
93 | 1 | * This method requires that you have implemented enter() and a form creator |
|
94 | * for the model |
||
95 | * |
||
96 | 1 | * @param Player $me The user who wants to create the model |
|
97 | 1 | * @param Closure|null $onSuccess The function to call on success |
|
98 | * @throws ForbiddenException |
||
99 | 1 | * @return mixed The response to show to the user |
|
100 | 1 | */ |
|
101 | 1 | protected function create(Player $me, $onSuccess = null) |
|
131 | |||
132 | /** |
||
133 | * Edit a model |
||
134 | * |
||
135 | * This method requires that you have implemented update() and a form creator |
||
136 | * for the model |
||
137 | * |
||
138 | * @param PermissionModel $model The model we want to edit |
||
139 | * @param Player $me The user who wants to edit the model |
||
140 | * @param string $type The name of the variable to pass to the view |
||
141 | * @throws ForbiddenException |
||
142 | * @return mixed The response to show to the user |
||
143 | */ |
||
144 | protected function edit(PermissionModel $model, Player $me, $type) |
||
167 | |||
168 | /** |
||
169 | * Find whether a player can delete a model |
||
170 | * |
||
171 | * @param Player $player The player who wants to delete the model |
||
172 | * @param PermissionModel $model The model that will be deleted |
||
173 | * @param bool $hard Whether to hard-delete the model instead of soft-deleting it |
||
174 | * @return bool |
||
175 | 1 | */ |
|
176 | protected function canDelete($player, $model, $hard = false) |
||
180 | |||
181 | /** |
||
182 | * Find whether a player can create a model |
||
183 | * |
||
184 | * @param Player $player The player who wants to create a model |
||
185 | * @return bool |
||
186 | */ |
||
187 | protected function canCreate($player) |
||
193 | |||
194 | /** |
||
195 | * Find whether a player can edit a model |
||
196 | * |
||
197 | * @param Player $player The player who wants to delete the model |
||
198 | * @param PermissionModel $model The model which will be edited |
||
199 | * @return bool |
||
200 | */ |
||
201 | protected function canEdit($player, $model) |
||
205 | 1 | ||
206 | 1 | /** |
|
207 | * Get a redirection response to a model |
||
208 | * |
||
209 | * Goes to a list of models of the same type if the provided model does not |
||
210 | * have a URL |
||
211 | * |
||
212 | * @param ModelInterface $model The model to redirect to |
||
213 | * @return Response |
||
214 | */ |
||
215 | protected function redirectTo($model) |
||
223 | 1 | ||
224 | /** |
||
225 | * Get a redirection response to a list of models |
||
226 | * |
||
227 | * @param ModelInterface $model The model to whose list we should redirect |
||
228 | * @return Response |
||
229 | */ |
||
230 | protected function redirectToList($model) |
||
237 | 1 | ||
238 | 1 | /** |
|
239 | * Dynamically get the form to show to the user |
||
240 | 1 | * |
|
241 | * @param \Model|null $model The model being edited, `null` if we're creating one |
||
242 | * @return ModelFormCreator |
||
243 | */ |
||
244 | private function getFormCreator($model = null) |
||
254 | 1 | ||
255 | /** |
||
256 | 1 | * Get a message to show to the user |
|
257 | * @todo Use the $escape parameter |
||
258 | 1 | * @param \ModelInterface|string $model The model (or type) to show a message for |
|
259 | 1 | * @param string $action The action that will be performed (softDelete, hardDelete, create or edit) |
|
260 | 1 | * @param string $status The message's status (confirm, error or success) |
|
261 | * @return string |
||
262 | */ |
||
263 | 1 | private function getMessage($model, $action, $status, $escape = true) |
|
289 | |||
290 | 1 | /** |
|
291 | * Get a list of messages to show to the user |
||
292 | 1 | * @param string $type The type of the model that the message refers to |
|
293 | * @param string $name The name of the model |
||
294 | * @return array |
||
295 | */ |
||
296 | 1 | protected function getMessages($type, $name = '') |
|
355 | } |
||
356 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.