X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=application%2Fcontrollers%2Fhelpers%2FSyjApi.php;h=92974c5ea775ecb3ab96ba29b7a7e491d5eb7e75;hb=1f6105289a49079809c2a4677b561bc82c62db88;hp=86ea00e3ff1cdc6fa6355843e81b5d164bddc496;hpb=190fd621df4920c56a422c03663874cddaa67d64;p=syj.git diff --git a/application/controllers/helpers/SyjApi.php b/application/controllers/helpers/SyjApi.php index 86ea00e..92974c5 100644 --- a/application/controllers/helpers/SyjApi.php +++ b/application/controllers/helpers/SyjApi.php @@ -1,5 +1,5 @@ _contentType = $contentType; } + public function setBodyJson($data) { + $this->setBody(json_encode($data)) + ->setContentType('application/json'); + return $this; + } + public function setBody($body) { $this->_body = (string)$body; return $this; @@ -45,6 +52,20 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ return $this->_code; } + public function setRedirect($url, $code = 0) { + $this->_redirect = (string)$url; + if (is_numeric($code) && (int)$code >= 300 && (int)$code < 400) { + $this->_code; + } else if (!isset($this->_code)) { + $this->code = 301; + } + return $this; + } + + public function getRedirect() { + return $this->_redirect; + } + public function setCheckIfNoneMatch($check) { $this->_checkIfNoneMatch = (boolean)$check; return $this; @@ -74,6 +95,10 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ $response->setHeader ('Etag', $etag); } + if ($this->_redirect) { + $response->setHeader ('Location', $this->_redirect); + } + $response->setHttpResponseCode($this->_code) ->setBody($this->_body); }