1 | <?php |
||
2 | namespace Mezon\Application; |
||
3 | |||
4 | /** |
||
5 | * Class AjaxMethodsTrait |
||
6 | * |
||
7 | * @package Application |
||
8 | * @subpackage AjaxMethodsTrait |
||
9 | * @author Dodonov A.A. |
||
10 | * @version v.1.0 (2019/09/27) |
||
11 | * @copyright Copyright (c) 2019, aeon.org |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * Base class of the ajax-application |
||
16 | */ |
||
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); |
||
0 ignored issues
–
show
|
|||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Method finishes ajax requests processing and returns result |
||
41 | */ |
||
42 | protected function ajaxRequestResult($result) |
||
43 | { |
||
44 | print(json_encode($result)); |
||
45 | |||
46 | die(0); |
||
0 ignored issues
–
show
|
|||
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) |
||
58 | { |
||
59 | print(json_encode([ |
||
60 | "message" => $message, |
||
61 | "code" => $code |
||
62 | ])); |
||
63 | |||
64 | die(0); |
||
0 ignored issues
–
show
|
|||
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.