1 | <?php |
||
25 | abstract class Controller implements ControllerInterface |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var ServerRequestInterface|Request |
||
30 | */ |
||
31 | protected $request; |
||
32 | |||
33 | /** |
||
34 | * @var ResponseInterface|Response |
||
35 | */ |
||
36 | protected $response; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $vars = []; |
||
42 | |||
43 | /** |
||
44 | * For URL parsing |
||
45 | */ |
||
46 | use UrlUtils; |
||
47 | |||
48 | /** |
||
49 | * Registers the current HTTP request and response |
||
50 | * |
||
51 | * @param ServerRequestInterface $request |
||
52 | * @param ResponseInterface $response |
||
53 | * |
||
54 | * @return Controller|$this|self|ControllerInterface |
||
55 | */ |
||
56 | 20 | public function register( |
|
63 | |||
64 | /** |
||
65 | * Gets updated HTTP response |
||
66 | * |
||
67 | * @return ResponseInterface |
||
68 | */ |
||
69 | 10 | public function getResponse() |
|
73 | |||
74 | /** |
||
75 | * Gets updated HTTP request |
||
76 | * |
||
77 | * @return ServerRequestInterface |
||
78 | */ |
||
79 | 10 | public function getRequest() |
|
83 | |||
84 | /** |
||
85 | * Sets a value to be used by render |
||
86 | * |
||
87 | * The key argument can be an associative array with values to be set |
||
88 | * or a string naming the passed value. If an array is given then the |
||
89 | * value will be ignored. |
||
90 | * |
||
91 | * Those values must be set in the request attributes so they can be used |
||
92 | * latter by any other middle ware in the stack. |
||
93 | * |
||
94 | * @param string|array $key |
||
95 | * @param mixed $value |
||
96 | * |
||
97 | * @return Controller|$this|self|ControllerInterface |
||
98 | */ |
||
99 | 8 | public function set($key, $value = null) |
|
110 | |||
111 | /** |
||
112 | * Returns the data that was set on controller action |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | 8 | public function getViewVars() |
|
120 | |||
121 | /** |
||
122 | * Enables or disables rendering |
||
123 | * |
||
124 | * @param bool $disable |
||
125 | * @return ControllerInterface|self|$this |
||
126 | */ |
||
127 | 6 | public function disableRendering($disable = true) |
|
132 | |||
133 | /** |
||
134 | * Changes the current rendering template |
||
135 | * |
||
136 | * @param string $template |
||
137 | * @return ControllerInterface|self|$this |
||
138 | */ |
||
139 | 2 | public function setView($template) |
|
144 | |||
145 | /** |
||
146 | * Redirects the flow to another route/path |
||
147 | * |
||
148 | * @param string $path the route or path to redirect to |
||
149 | * |
||
150 | * @return Controller|self|$this |
||
151 | */ |
||
152 | 4 | public function redirect($path) |
|
160 | |||
161 | /** |
||
162 | * Get the routed request attributes |
||
163 | * |
||
164 | * @param null|string $name |
||
165 | * @param mixed $default |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | public function getRouteAttributes($name = null, $default = null) |
||
185 | |||
186 | /** |
||
187 | * Register a variable value |
||
188 | * |
||
189 | * @param string $key |
||
190 | * @param mixed $value |
||
191 | * |
||
192 | * @return Controller|$this|self |
||
193 | */ |
||
194 | 8 | protected function registerVar($key, $value) |
|
199 | |||
200 | /** |
||
201 | * Creates a redirect response for provided path |
||
202 | * |
||
203 | * @param string $path |
||
204 | * |
||
205 | * @return Response |
||
206 | */ |
||
207 | 4 | protected function createRedirectResponse($path) |
|
213 | } |