Changeset 1471
- Timestamp:
- 03/29/08 21:35:39 (5 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/response/stubBaseResponse.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/ipo/response/stubCookie.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ipo/response/stubResponse.php (modified) (7 diffs)
- trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/response/stubBaseResponseTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/response/stubBaseResponse.php
r1223 r1471 22 22 { 23 23 /** 24 * current php sapi 25 * 26 * @var string 27 */ 28 protected $sapi; 29 /** 30 * http version to be used 31 * 32 * @var string 33 */ 34 protected $version; 35 /** 36 * the status code to be send 37 * 38 * @var int 39 */ 40 protected $statusCode = null; 41 /** 24 42 * list of headers for this response 25 43 * 26 44 * @var array<string,string> 27 45 */ 28 protected $headers = array();46 protected $headers = array(); 29 47 /** 30 48 * list of cookies for this response … … 32 50 * @var array<string,stubCookie> 33 51 */ 34 protected $cookies = array();52 protected $cookies = array(); 35 53 /** 36 54 * data to send as body of response … … 38 56 * @var string 39 57 */ 40 protected $data = null; 58 protected $data = null; 59 60 /** 61 * constructor 62 * 63 * @param string $sapi optional current php sapi 64 * @param string $version optional http version 65 */ 66 public function __construct($sapi = PHP_SAPI, $version = '1.1') 67 { 68 $this->sapi = $sapi; 69 $this->version = $version; 70 } 41 71 42 72 /** … … 45 75 public function clear() 46 76 { 47 $this->header = array(); 48 $this->cookie = array(); 49 $this->data = null; 77 $this->statusCode = null; 78 $this->headers = array(); 79 $this->cookies = array(); 80 $this->data = null; 81 } 82 83 /** 84 * sets the http version 85 * 86 * The version should be a string like '1.0' or '1.1'. 87 * 88 * @param string $version 89 */ 90 public function setVersion($version) 91 { 92 $this->version = $version; 93 } 94 95 /** 96 * returns the http version 97 * 98 * @return string 99 */ 100 public function getVersion() 101 { 102 return $this->version; 103 } 104 105 /** 106 * sets the status code to be send 107 * 108 * This needs only to be done if another status code then the default one 109 * should be send. 110 * 111 * @param int $statusCode 112 */ 113 public function setStatusCode($statusCode) 114 { 115 $this->statusCode = $statusCode; 116 } 117 118 /** 119 * returns status code to be send 120 * 121 * If return value is <null> the default one will be send. 122 * 123 * @return int 124 */ 125 public function getStatusCode() 126 { 127 return $this->statusCode; 50 128 } 51 129 … … 84 162 * returns the list of cookies 85 163 * 86 * @return array<st ubCookie>164 * @return array<string,stubCookie> 87 165 */ 88 166 public function getCookies() … … 126 204 public function send() 127 205 { 206 if (null !== $this->statusCode) { 207 if ('cgi' === $this->sapi) { 208 $this->header('Status: ' . $this->statusCode); 209 } else { 210 $this->header('HTTP/' . $this->version . ' ' . $this->statusCode); 211 } 212 } 213 128 214 // send the headers 129 215 foreach ($this->headers as $name => $value) { 130 header($name . ': ' . $value);216 $this->header($name . ': ' . $value); 131 217 } 132 218 133 219 // send the cookies 134 220 foreach ($this->cookies as $cookie) { 135 setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());221 $cookie->send(); 136 222 } 137 223 138 224 // and finally send the data 139 echo $this->data; 225 $this->sendData($this->data); 226 } 227 228 /** 229 * helper method to send the header 230 * 231 * @param string $header 232 */ 233 // @codeCoverageIgnoreStart 234 protected function header($header) 235 { 236 header($header); 237 } 238 // @codeCoverageIgnoreEnd 239 240 /** 241 * helper method to send the data 242 * 243 * @param string $data 244 */ 245 // @codeCoverageIgnoreStart 246 protected function sendData($data) 247 { 248 echo $data; 140 249 flush(); 141 250 } 251 // @codeCoverageIgnoreEnd 142 252 } 143 253 ?> trunk/src/main/php/net/stubbles/ipo/response/stubCookie.php
r713 r1471 70 70 * @param string $value value of the cookie 71 71 */ 72 p rotectedfunction __construct($name, $value)72 public function __construct($name, $value) 73 73 { 74 74 $this->name = $name; … … 218 218 return $this->httpOnly; 219 219 } 220 221 /** 222 * sends the cookie 223 */ 224 // @codeCoverageIgnoreStart 225 public function send() 226 { 227 setcookie($this->name, $this->value, $this->expires, $this->path, $this->domain, $this->secure, $this->httpOnly); 228 } 229 // @codeCoverageIgnoreEnd 220 230 } 221 231 ?> trunk/src/main/php/net/stubbles/ipo/response/stubResponse.php
r1223 r1471 23 23 */ 24 24 public function clear(); 25 25 26 /** 27 * sets the http version 28 * 29 * The version should be a string like '1.0' or '1.1'. 30 * 31 * @param string $version 32 */ 33 public function setVersion($version); 34 35 /** 36 * returns the http version 37 * 38 * @return string 39 */ 40 public function getVersion(); 41 42 /** 43 * sets the status code to be send 44 * 45 * This needs only to be done if another status code then the default one 46 * should be send. 47 * 48 * @param int $statusCode 49 */ 50 public function setStatusCode($statusCode); 51 52 /** 53 * returns status code to be send 54 * 55 * If return value is <null> the default one will be send. 56 * 57 * @return int 58 */ 59 public function getStatusCode(); 60 26 61 /** 27 62 * add a header to the response … … 31 66 */ 32 67 public function addHeader($name, $value); 33 68 34 69 /** 35 70 * returns the list of headers … … 38 73 */ 39 74 public function getHeaders(); 40 75 41 76 /** 42 77 * add a cookie to the response … … 45 80 */ 46 81 public function setCookie(stubCookie $cookie); 47 82 48 83 /** 49 84 * returns the list of cookies 50 85 * 51 * @return array<st ubCookie>86 * @return array<string,stubCookie> 52 87 */ 53 88 public function getCookies(); 54 89 55 90 /** 56 91 * write data into the response … … 59 94 */ 60 95 public function write($data); 61 96 62 97 /** 63 98 * returns the data written so far … … 66 101 */ 67 102 public function getData(); 68 103 69 104 /** 70 105 * replaces the data written so far with the new data … … 73 108 */ 74 109 public function replaceData($data); 75 110 76 111 /** 77 112 * send the response out trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php
r1434 r1471 65 65 $suite->addTestFile($dir . '/request/filters/provider/stubSimpleFilterProviderTestCase.php'); 66 66 67 $suite->addTestFile($dir . '/response/stubBaseResponseTestCase.php'); 67 68 $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); 68 69
