1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base controller class. |
4
|
|
|
* |
5
|
|
|
* @copyright YetiForce Sp. z o.o. |
6
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
7
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace App\Controller; |
11
|
|
|
|
12
|
|
|
use App\Request; |
13
|
|
|
|
14
|
|
|
abstract class Base |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** @var \App\Headers Headers instance. */ |
17
|
|
|
public $headers; |
18
|
|
|
|
19
|
|
|
/** @var Request Request object. */ |
20
|
|
|
protected $request; |
21
|
|
|
|
22
|
|
|
/** @var string Module name. */ |
23
|
|
|
protected $moduleName; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Construct. |
27
|
|
|
* |
28
|
|
|
* @param \App\Request $request |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Request $request) |
31
|
|
|
{ |
32
|
|
|
$this->headers = \App\Controller\Headers::getInstance(); |
|
|
|
|
33
|
|
|
if (\App\Config::get('csrfProtection')) { |
34
|
|
|
require_once ROOT_DIRECTORY . '/config/csrf_config.php'; |
35
|
|
|
\CsrfMagic\Csrf::init(); |
36
|
|
|
} |
37
|
|
|
$this->request = $request; |
38
|
|
|
$this->moduleName = $request->getModule(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Login required. |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function loginRequired(): bool |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
return true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Main action. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
abstract public function process(); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Validates request. Checks type of request. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
abstract public function validateRequest(); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Action invoke before process. |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
abstract public function preProcess(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Action invoke after process. |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
abstract public function postProcess(); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Action invoke before process for AJAX. |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
abstract public function preProcessAjax(); |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Action invoke after process for AJAX. |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
abstract public function postProcessAjax(); |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Send headers. |
95
|
|
|
*/ |
96
|
|
|
public function sendHeaders() |
97
|
|
|
{ |
98
|
|
|
$this->headers->send(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Error handler. |
103
|
|
|
* |
104
|
|
|
* @param string $errno |
|
|
|
|
105
|
|
|
* @param string $errstr |
106
|
|
|
* @param string $errfile |
107
|
|
|
* @param string $errline |
108
|
|
|
* @param string $errcontext |
109
|
|
|
* |
110
|
|
|
* @return void |
|
|
|
|
111
|
|
|
*/ |
112
|
|
|
public static function exceptionErrorHandler(int $errno, string $errstr, $errfile, $errline, $errcontext) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
throw new \App\Exceptions\AppException($errstr, $errno); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.