1 | <?php |
||
27 | abstract class Controller |
||
28 | { |
||
29 | /** |
||
30 | * @var Application |
||
31 | */ |
||
32 | protected $application; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | * |
||
37 | * @param Application $app |
||
38 | */ |
||
39 | public function __construct(Application $app) |
||
43 | |||
44 | /** |
||
45 | * Returns a new AccessDeniedException. |
||
46 | * |
||
47 | * @param string $message |
||
48 | * |
||
49 | * @return AccessDeniedException |
||
50 | */ |
||
51 | protected function createAccessDeniedException($message = 'Access Denied.') |
||
55 | |||
56 | /** |
||
57 | * Returns a new NotFoundHttpException. |
||
58 | * |
||
59 | * @param string $message |
||
60 | * |
||
61 | * @return NotFoundHttpException |
||
62 | */ |
||
63 | protected function createNotFoundHttpException($message = 'Not Found') |
||
67 | |||
68 | /** |
||
69 | * Throws an exception unless the attributes are granted against the current authentication token. |
||
70 | * |
||
71 | * @param mixed $roles |
||
72 | * @param string $message |
||
73 | * |
||
74 | * @throws AccessDeniedException |
||
75 | */ |
||
76 | protected function denyAccessUnlessGranted($roles, $message = 'Access Denied.') |
||
85 | |||
86 | /** |
||
87 | * Gets Doctrine Entity Manager. |
||
88 | * |
||
89 | * @return EntityManager |
||
90 | */ |
||
91 | public function getEntityManager() |
||
95 | |||
96 | /** |
||
97 | * Gets the environment. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getEnv() |
||
105 | |||
106 | /** |
||
107 | * Gets the Form Factory. |
||
108 | * |
||
109 | * @return FormFactory |
||
110 | */ |
||
111 | public function getFormFactory() |
||
115 | |||
116 | /** |
||
117 | * Gets the project root directory. |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getRootDir() |
||
125 | |||
126 | /** |
||
127 | * Gets the router. |
||
128 | * |
||
129 | * @return UrlGenerator |
||
130 | */ |
||
131 | public function getRouter() |
||
135 | |||
136 | /** |
||
137 | * Gets the session. |
||
138 | * |
||
139 | * @return Session |
||
140 | */ |
||
141 | public function getSession() |
||
145 | |||
146 | /** |
||
147 | * Gets the Twig service. |
||
148 | * |
||
149 | * @return Environment |
||
150 | */ |
||
151 | public function getTwig() |
||
155 | |||
156 | /** |
||
157 | * Gets the current authenticated user or null if not logged in. |
||
158 | * |
||
159 | * @return User|null |
||
160 | */ |
||
161 | public function getUser() |
||
170 | |||
171 | /** |
||
172 | * Redirects the user to another route. |
||
173 | * |
||
174 | * @param string $route |
||
175 | * @param array $parameters |
||
176 | * @param int $status |
||
177 | * |
||
178 | * @return RedirectResponse |
||
179 | */ |
||
180 | public function redirect($route, $parameters = [], $status = 302) |
||
184 | |||
185 | /** |
||
186 | * Redirects the user to another URL. |
||
187 | * |
||
188 | * @param string $url The URL to redirect to |
||
189 | * @param int $status The status code (302 by default) |
||
190 | * |
||
191 | * @return RedirectResponse |
||
192 | */ |
||
193 | public function redirectTo($url, $status = 302) |
||
197 | |||
198 | /** |
||
199 | * Generates a path from the given parameters. |
||
200 | * |
||
201 | * @param string $route |
||
202 | * @param mixed $parameters |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | public function path($route, $parameters = []) |
||
210 | |||
211 | /** |
||
212 | * Generates an absolute URL from the given parameters. |
||
213 | * |
||
214 | * @param string $route |
||
215 | * @param mixed $parameters |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function url($route, $parameters = []) |
||
223 | |||
224 | /** |
||
225 | * Renders a twig template. |
||
226 | * |
||
227 | * @param string $name |
||
228 | * @param array $context |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | public function render($name, array $context = []) |
||
236 | |||
237 | /** |
||
238 | * Adds a flash message. |
||
239 | * |
||
240 | * @param string $type |
||
241 | * @param string $message |
||
242 | */ |
||
243 | public function flash($type, $message) |
||
247 | |||
248 | /** |
||
249 | * Checks if user is granted a role. |
||
250 | * |
||
251 | * @param string $role |
||
252 | * |
||
253 | * @return bool |
||
254 | */ |
||
255 | public function isGranted($role) |
||
259 | |||
260 | /** |
||
261 | * Get a service from the container |
||
262 | * |
||
263 | * @param string $service |
||
264 | * |
||
265 | * @return mixed |
||
266 | */ |
||
267 | public function get($service) |
||
271 | |||
272 | /** |
||
273 | * Gets a service from the container. |
||
274 | * |
||
275 | * @param string $property |
||
276 | * |
||
277 | * @return mixed |
||
278 | */ |
||
279 | public function __get($property) |
||
283 | } |
||
284 |