1 | <?php |
||
30 | abstract class AbstractController |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * Holds the views per controller request |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private $_viewArray = []; |
||
39 | |||
40 | /** |
||
41 | * Holds the request |
||
42 | * |
||
43 | * @var Request |
||
44 | */ |
||
45 | protected $request; |
||
46 | |||
47 | /** |
||
48 | * AbstractController constructor. |
||
49 | * |
||
50 | * @param Request $request The request object |
||
51 | */ |
||
52 | public function __construct(Request $request) |
||
56 | |||
57 | /** |
||
58 | * Returns the service locator |
||
59 | * |
||
60 | * @return ServiceLocator |
||
61 | */ |
||
62 | public function getServiceLocator() :ServiceLocator |
||
66 | |||
67 | /** |
||
68 | * Returns the session manager |
||
69 | * |
||
70 | * @return SessionManagerService|ServiceInterface |
||
71 | * |
||
72 | * @throws ServiceNotFoundException |
||
73 | */ |
||
74 | public function getSessionManager() :SessionManagerService |
||
78 | |||
79 | /** |
||
80 | * Returns the view controller |
||
81 | * |
||
82 | * @return ViewController |
||
83 | */ |
||
84 | public function getView() :ViewController |
||
99 | |||
100 | /** |
||
101 | * Returns the orm/entity manager |
||
102 | * |
||
103 | * @return DbService|ServiceInterface |
||
104 | * |
||
105 | * @throws ServiceNotFoundException |
||
106 | */ |
||
107 | public function getDb() :DbService |
||
111 | |||
112 | /** |
||
113 | * Render view with given template |
||
114 | * |
||
115 | * @param string $template The template to be rendered |
||
116 | * @param array $variables The variables for the template |
||
117 | * |
||
118 | * @return Response |
||
119 | * |
||
120 | * @throws ServiceNotFoundException |
||
121 | */ |
||
122 | public function render(string $template = '', $variables = []) :Response |
||
144 | |||
145 | /** |
||
146 | * Check if user is permitted based on his role(s) |
||
147 | * |
||
148 | * @param array $roles The corresponding user roles |
||
149 | * |
||
150 | * @return bool|null |
||
151 | * |
||
152 | * @throws ServiceNotFoundException |
||
153 | */ |
||
154 | public function isPermitted($roles = []) |
||
161 | |||
162 | /** |
||
163 | * Redirect to specific uri |
||
164 | * |
||
165 | * @param string $uri The target uri |
||
166 | * |
||
167 | * @return bool |
||
168 | * |
||
169 | * @throws ServiceNotFoundException |
||
170 | * @throws InvalidArgumentException |
||
171 | */ |
||
172 | public function redirect(string $uri) :bool |
||
178 | |||
179 | /** |
||
180 | * Set a generic text token which is valid for exactly one call |
||
181 | * |
||
182 | * @param string $key Key for the flash message |
||
183 | * @param string $message Content for the flash message |
||
184 | * |
||
185 | * @return void |
||
186 | * |
||
187 | * @throws ServiceNotFoundException |
||
188 | */ |
||
189 | public function setFlashMessage(string $key, string $message) |
||
194 | |||
195 | /** |
||
196 | * Retrieve a flash message |
||
197 | * |
||
198 | * @param string $key The flash message key |
||
199 | * |
||
200 | * @return string|null |
||
201 | * |
||
202 | * @throws ServiceNotFoundException |
||
203 | */ |
||
204 | public function getFlashMessage(string $key) |
||
209 | |||
210 | /** |
||
211 | * Get the url for a specific route name |
||
212 | * |
||
213 | * @param string $name Name of the route |
||
214 | * @param array $parameters Apply parameters where necessary |
||
215 | * @param bool $absolute Return an absolute url with host as prefix |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function route(string $name, array $parameters = [], $absolute = false) |
||
223 | |||
224 | /** |
||
225 | * Return the current request object |
||
226 | * |
||
227 | * @return Request |
||
228 | */ |
||
229 | public function getRequest() :Request |
||
233 | |||
234 | /** |
||
235 | * Add default assets for every action |
||
236 | */ |
||
237 | protected function addAssets() { |
||
240 | |||
241 | } |