1 | <?php |
||
11 | abstract class Controller |
||
12 | { |
||
13 | /** |
||
14 | * Server request |
||
15 | * @var ServerRequestInterface |
||
16 | **/ |
||
17 | protected $request = null; |
||
18 | |||
19 | /** |
||
20 | * Response |
||
21 | * @var ResponseInterface |
||
22 | **/ |
||
23 | protected $response = null; |
||
24 | |||
25 | /** |
||
26 | * Flash |
||
27 | * @var Flash |
||
28 | **/ |
||
29 | protected $flash = null; |
||
30 | |||
31 | /** |
||
32 | * Run the controller |
||
33 | * |
||
34 | * @return ResponseInterface |
||
35 | */ |
||
36 | abstract public function run(); |
||
37 | |||
38 | /** |
||
39 | * Get request, set for controller |
||
40 | * |
||
41 | * @return ServerRequestInterface |
||
42 | */ |
||
43 | 1 | public function getRequest() |
|
47 | |||
48 | /** |
||
49 | * Get response. set for controller |
||
50 | * |
||
51 | * @return ResponseInterface |
||
52 | */ |
||
53 | 15 | public function getResponse() |
|
57 | |||
58 | /** |
||
59 | * Run the controller as function |
||
60 | * |
||
61 | * @param ServerRequestInterface $request |
||
62 | * @param ResponseInterface $response |
||
63 | * @return ResponseInterface |
||
64 | */ |
||
65 | 14 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response) |
|
72 | |||
73 | /** |
||
74 | * Set the flash message and/or return the flash object. |
||
75 | * |
||
76 | * @param mixed $type flash type, eg. 'error', 'notice' or 'success' |
||
77 | * @param mixed $message flash message |
||
78 | * @return Flash |
||
79 | */ |
||
80 | 1 | public function flash($type = null, $message = null) |
|
87 | |||
88 | /** |
||
89 | * Check if response is 2xx succesful, or empty |
||
90 | * |
||
91 | * @return boolean |
||
92 | */ |
||
93 | 14 | public function isSuccessful() |
|
99 | |||
100 | /** |
||
101 | * Check if response is a 3xx redirect |
||
102 | * |
||
103 | * @return boolean |
||
104 | */ |
||
105 | 14 | public function isRedirection() |
|
111 | |||
112 | /** |
||
113 | * Check if response is a 4xx client error |
||
114 | * |
||
115 | * @return boolean |
||
116 | */ |
||
117 | 14 | public function isClientError() |
|
123 | |||
124 | /** |
||
125 | * Check if response is a 5xx redirect |
||
126 | * |
||
127 | * @return boolean |
||
128 | */ |
||
129 | 14 | public function isServerError() |
|
133 | |||
134 | /** |
||
135 | * Check if response is 4xx or 5xx error |
||
136 | * |
||
137 | * @return boolean |
||
138 | */ |
||
139 | 13 | public function isError() |
|
143 | |||
144 | /** |
||
145 | * Get status code of response |
||
146 | * |
||
147 | * @return int |
||
148 | */ |
||
149 | 14 | protected function getResponseStatusCode() |
|
155 | } |
||
156 | |||
157 |
Adding braces to control structures avoids accidental mistakes as your code changes: