Total Complexity | 3 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | trait AjaxMethodsTrait |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Validating authorization for ajax requests |
||
22 | * |
||
23 | * Must be overriden in the base class |
||
24 | */ |
||
25 | abstract protected function validateAuthorizationForAjaxRequests(); |
||
26 | |||
27 | /** |
||
28 | * Method finishes ajax requests processing |
||
29 | */ |
||
30 | protected function ajaxRequestSuccess() |
||
31 | { |
||
32 | print(json_encode([ |
||
33 | "code" => 0 |
||
34 | ])); |
||
35 | |||
36 | die(0); |
||
|
|||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Method finishes ajax requests processing and returns result |
||
41 | */ |
||
42 | protected function ajaxRequestResult($result) |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Method finishes ajax requests processing |
||
51 | * |
||
52 | * @param string $message |
||
53 | * Error message |
||
54 | * @param int $code |
||
55 | * Error code |
||
56 | */ |
||
57 | protected function ajaxRequestError(string $message, int $code = - 1) |
||
65 | } |
||
66 | } |
||
67 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.