class_BaseResponse.php
Go to the documentation of this file.00001 <?php
00027 class BaseResponse extends BaseFrameworkSystem {
00031 private $responseStatus = "200 OK";
00032
00036 private $responseHeaders = array();
00037
00041 private $cookies = array();
00042
00046 private $responseBody = "";
00047
00051 private $templateInstance = null;
00052
00056 private $fatalMessages = array();
00057
00064 protected function __construct ($className) {
00065
00066 parent::__construct($className);
00067
00068
00069 $this->removeNumberFormaters();
00070 $this->removeSystemArray();
00071 }
00072
00079 public final function setResponseStatus ($status) {
00080 $this->responseStatus = (string) $status;
00081 }
00082
00090 public final function addHeader ($name, $value) {
00091 $this->responseHeaders[$name] = $value;
00092 }
00093
00099 public final function resetResponseHeaders () {
00100 $this->responseHeaders = array();
00101 }
00102
00109 public final function writeToBody ($output) {
00110 $this->responseBody .= $output;
00111 }
00112
00119 public final function setResponseBody ($output) {
00120 $this->responseBody = $output;
00121 }
00122
00130 public final function addFatalMessage ($messageId) {
00131
00132 $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId);
00133 }
00134
00141 public final function addFatalMessagePlain ($message) {
00142
00143 $this->fatalMessages[] = $message;
00144 }
00145
00155 public function flushBuffer ($force = false) {
00156 if ((headers_sent()) && ($force === false)) {
00157
00158 throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00159 } elseif (!headers_sent()) {
00160
00161 header("HTTP/1.1 {$this->responseStatus}");
00162
00163
00164 $now = gmdate('D, d M Y H:i:s') . ' GMT';
00165
00166
00167 $this->addHeader('Expired', $now);
00168 $this->addHeader('Last-Modified', $now);
00169 $this->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
00170 $this->addHeader('Pragma', 'no-cache');
00171
00172
00173
00174
00175
00176 foreach ($this->responseHeaders as $name => $value) {
00177 header("{$name}: {$value}");
00178
00179 }
00180
00181
00182 if (count($this->cookies) > 0) {
00183
00184 $cookieString = implode(" ", $this->cookies);
00185 header("Set-Cookie: {$cookieString}");
00186
00187
00188 $this->cookies = array();
00189 }
00190 }
00191
00192
00193 if (count($this->fatalMessages) == 0) {
00194
00195 $this->getWebOutputInstance()->output($this->responseBody);
00196 } else {
00197
00198 $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages);
00199
00200
00201 $this->getWebOutputInstance()->output($this->responseBody);
00202 }
00203
00204
00205 $this->setResponseBody("");
00206 $this->resetResponseHeaders();
00207 }
00208 }
00209
00210
00211 ?>