| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\App\Controllers;
- use \ThurData\Servers\KerioEmail\Core\UI\View;
- use \ThurData\Servers\KerioEmail\Core\Http\JsonResponse;
- use \ThurData\Servers\KerioEmail\Core\Http\RedirectResponse;
- use \ThurData\Servers\KerioEmail\Core\Http\Response;
- class ResponseResolver
- {
- use \ThurData\Servers\KerioEmail\Core\Traits\Lang;
- use \ThurData\Servers\KerioEmail\Core\Traits\Smarty;
- use \ThurData\Servers\KerioEmail\Core\Traits\OutputBuffer;
- use \ThurData\Servers\KerioEmail\Core\Traits\IsAdmin;
- use \ThurData\Servers\KerioEmail\Core\UI\Traits\RequestObjectHandler;
- use \ThurData\Servers\KerioEmail\Core\Traits\Template;
- protected $response = null;
- /**
- * @var null|HttpController
- */
- protected $pageController = null;
- public function __construct($response = null)
- {
- $this->setResponse($response);
- $this->loadSmarty();
- }
- /**
- * @param null $response
- * @return $this
- */
- public function setResponse($response = null)
- {
- if ($response)
- {
- $this->response = $response;
- }
- return $this;
- }
- /**
- * resolves the response
- */
- public function resolve()
- {
- if ($this->response instanceof View)
- {
- $this->resolveView();
- }
- if ($this->response instanceof JsonResponse)
- {
- $this->resolveJson();
- }
- elseif ($this->response instanceof RedirectResponse)
- {
- $this->resolveRedirect();
- }
- elseif ($this->response instanceof Response)
- {
- $this->prepareResponse();
- return $this->resolveResponse();
- }
- }
- /**
- * resolve View object to the processable response
- */
- public function resolveView()
- {
- /**
- * @var $this->response \ThurData\Servers\KerioEmail\Core\UI\View
- */
- $this->response->validateAcl($this->isAdmin());
- $this->response = $this->response->getResponse();
- }
- public function prepareResponse()
- {
- $this->response->setLang($this->lang);
- $this->response->setTemplateName($this->getTemplateName());
- $this->response->setTemplateDir($this->getTemplateDir());
- //$this->smarty->setTemplateDir();
- }
- /**
- * resolve \ThurData\Servers\KerioEmail\Core\Http\JsonResponse
- */
- public function resolveJson()
- {
- $this->cleanOutputBuffer();
- /**
- * @var \ThurData\Servers\KerioEmail\Core\Http\JsonResponse
- */
- $this->response->send();
- die();
- }
- public function resolveRedirect()
- {
- /**
- * @var \ThurData\Servers\KerioEmail\Core\Http\RedirectResponse
- */
- die($this->response->send());
- }
- public function resolveResponse()
- {
- return $this->response->getHtmlResponse($this);
- }
- /**
- * @param null|HttpController $pageController
- */
- public function setPageController($pageController)
- {
- $this->pageController = $pageController;
- return $this;
- }
- /**
- * @return HttpController|null
- */
- public function getPageController()
- {
- return $this->pageController;
- }
- }
|