| 1 | <?php |
||
| 16 | class BaseController |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @param string $packageRoot |
||
| 20 | * @param Request $request |
||
| 21 | */ |
||
| 22 | public function __construct($packageRoot, Request $request) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return Response|null |
||
| 31 | */ |
||
| 32 | public function getResponse() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param Response $response |
||
| 39 | */ |
||
| 40 | public function setResponse(Response $response) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Create Response from template. |
||
| 47 | * |
||
| 48 | * @param string $name |
||
| 49 | * @param array $data |
||
| 50 | */ |
||
| 51 | public function setView($name = '', array $data = []) |
||
| 52 | { |
||
| 53 | $this->response = new Response; |
||
| 54 | $this->response->setContent((new Native($this->packageRoot, $this->request))->getContent($name, $data)); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Create Response from content. |
||
| 59 | * |
||
| 60 | * @param string $content |
||
| 61 | */ |
||
| 62 | public function setContent($content) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Redirect to URL with statusCode and terminate app. |
||
| 70 | * |
||
| 71 | * @param null $url |
||
| 72 | * @param int $statusCode |
||
| 73 | */ |
||
| 74 | public function setRedirect($url = null, $statusCode = 307) |
||
| 79 | |||
| 80 | protected $packageRoot; |
||
| 81 | protected $request; |
||
| 82 | protected $response; |
||
| 83 | } |