class_HttpResponse.php
Go to the documentation of this file.00001 <?php
00027 class HttpResponse extends BaseResponse implements Responseable {
00033 protected function __construct () {
00034
00035 parent::__construct(__CLASS__);
00036 }
00037
00044 public final static function createHttpResponse (ManageableApplication $appInstance) {
00045
00046 $responseInstance = new HttpResponse();
00047
00048
00049 $responseInstance->setApplicationInstance($appInstance);
00050
00051
00052 $responseInstance->initTemplateEngine($appInstance);
00053
00054
00055 return $responseInstance;
00056 }
00057
00064 public final function initTemplateEngine (ManageableApplication $appInstance) {
00065 $this->setTemplateInstance($this->prepareTemplateInstance($appInstance));
00066 }
00067
00082 public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) {
00083
00084
00085 if (headers_sent()) {
00086
00087
00088 throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00089 }
00090
00091
00092 if ($encrypted === true) {
00093 }
00094
00095
00096 $_COOKIE[$cookieName] = $cookieValue;
00097
00098
00099 if (is_null($expires)) {
00100 $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire'));
00101 }
00102
00103 $path = $this->getConfigInstance()->readConfig('cookie_path');
00104 $domain = $this->getConfigInstance()->readConfig('cookie_domain');
00105
00106 setcookie($cookieName, $cookieValue, $expires);
00107
00108 return;
00109
00110
00111 $cookieString = $cookieName . "=" . $cookieValue . "; ";
00112 $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT";
00113
00114
00115
00116 $this->cookies[$cookieName] = $cookieString;
00117 }
00118
00127 public function redirectToConfiguredUrl ($configEntry) {
00128
00129 if (headers_sent()) {
00130
00131 throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00132 }
00133
00134
00135 $this->getTemplateInstance()->assignApplicationData($this->getApplicationInstance());
00136
00137
00138 $url = $this->getConfigInstance()->readConfig($configEntry);
00139
00140
00141 $url = $this->getTemplateInstance()->compileRawCode($url);
00142
00143
00144 if (substr(strtolower($url), 0, 4) != "http") {
00145
00146 if (substr($url, 0, 1) == "/") $url = substr($url, 1);
00147
00148
00149 $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url;
00150 }
00151
00152
00153 $this->addHeader("Location", $url);
00154
00155
00156 $this->setResponseStatus("301 Moved Permanently");
00157
00158
00159 $this->setResponseBody("");
00160
00161
00162 $this->flushBuffer();
00163
00164
00165 exit();
00166 }
00167
00174 public function expireCookie ($cookieName) {
00175
00176 if (isset($_COOKIE[$cookieName])) {
00177
00178 $this->addCookie($cookieName, "", false, (time() - 1200));
00179
00180
00181 unset($_COOKIE[$cookieName]);
00182 }
00183 }
00184
00191 public function refreshCookie ($cookieName) {
00192
00193 if (isset($_COOKIE[$cookieName])) {
00194
00195 $this->addCookie($cookieName, $_COOKIE[$cookieName], false);
00196 }
00197 }
00198
00204 public function getDefaultCommand () {
00205 $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
00206 return $defaultCommand;
00207 }
00208 }
00209
00210
00211 ?>