Changeset 1478
- Timestamp:
- 03/30/08 16:34:02 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/response/stubBaseResponse.php
r1471 r1478 34 34 protected $version; 35 35 /** 36 * thestatus code to be send36 * status code to be send 37 37 * 38 38 * @var int 39 39 */ 40 protected $statusCode = null; 40 protected $statusCode; 41 /** 42 * status message to be send 43 * 44 * @var string 45 */ 46 protected $reasonPhrase; 41 47 /** 42 48 * list of headers for this response … … 44 50 * @var array<string,string> 45 51 */ 46 protected $headers = array();52 protected $headers = array(); 47 53 /** 48 54 * list of cookies for this response … … 50 56 * @var array<string,stubCookie> 51 57 */ 52 protected $cookies = array();58 protected $cookies = array(); 53 59 /** 54 60 * data to send as body of response … … 56 62 * @var string 57 63 */ 58 protected $data = null;64 protected $data; 59 65 60 66 /** 61 67 * constructor 62 68 * 69 * @param string $version optional http version 63 70 * @param string $sapi optional current php sapi 64 * @param string $version optional http version65 */66 public function __construct($sapi = PHP_SAPI, $version = '1.1')67 {71 */ 72 public function __construct($version = '1.1', $sapi = PHP_SAPI) 73 { 74 $this->version = $version; 68 75 $this->sapi = $sapi; 69 $this->version = $version;70 76 } 71 77 … … 75 81 public function clear() 76 82 { 77 $this->statusCode = null; 78 $this->headers = array(); 79 $this->cookies = array(); 80 $this->data = null; 83 $this->statusCode = null; 84 $this->reasonPhrase = null; 85 $this->headers = array(); 86 $this->cookies = array(); 87 $this->data = null; 81 88 } 82 89 … … 109 116 * should be send. 110 117 * 111 * @param int $statusCode 112 */ 113 public function setStatusCode($statusCode) 114 { 115 $this->statusCode = $statusCode; 118 * @param int $statusCode 119 * @param string $reasonPhrase optional 120 */ 121 public function setStatusCode($statusCode, $reasonPhrase = null) 122 { 123 $this->statusCode = $statusCode; 124 $this->reasonPhrase = $reasonPhrase; 116 125 } 117 126 … … 206 215 if (null !== $this->statusCode) { 207 216 if ('cgi' === $this->sapi) { 208 $this->header('Status: ' . $this->statusCode );217 $this->header('Status: ' . $this->statusCode . ' ' . $this->reasonPhrase); 209 218 } else { 210 $this->header('HTTP/' . $this->version . ' ' . $this->statusCode );219 $this->header('HTTP/' . $this->version . ' ' . $this->statusCode . ' ' . $this->reasonPhrase); 211 220 } 212 221 } trunk/src/main/php/net/stubbles/ipo/response/stubResponse.php
r1471 r1478 46 46 * should be send. 47 47 * 48 * @param int $statusCode 48 * @param int $statusCode 49 * @param string $reasonPhrase optional 49 50 */ 50 public function setStatusCode($statusCode );51 public function setStatusCode($statusCode, $reasonPhrase = null); 51 52 52 53 /** trunk/src/test/php/net/stubbles/ipo/response/stubBaseResponseTestCase.php
r1471 r1478 44 44 $this->assertEquals('1.0', $this->response->getVersion()); 45 45 46 $response = new stubBaseResponse( PHP_SAPI,'1.0');46 $response = new stubBaseResponse('1.0'); 47 47 $this->assertEquals('1.0', $response->getVersion()); 48 48 } … … 67 67 public function statusCodeInCgiSapi() 68 68 { 69 $this->response = $this->getMock('stubBaseResponse', array('header', 'sendData'), array(' cgi', '1.1'));69 $this->response = $this->getMock('stubBaseResponse', array('header', 'sendData'), array('1.1', 'cgi')); 70 70 $this->assertNull($this->response->getStatusCode()); 71 $this->response->setStatusCode(404 );72 $this->response->expects($this->once())->method('header')->with($this->equalTo('Status: 404 '));71 $this->response->setStatusCode(404, 'Not Found'); 72 $this->response->expects($this->once())->method('header')->with($this->equalTo('Status: 404 Not Found')); 73 73 $this->response->send(); 74 74 $this->response->clear(); … … 84 84 { 85 85 $this->assertNull($this->response->getStatusCode()); 86 $this->response->setStatusCode(404 );87 $this->response->expects($this->once())->method('header')->with($this->equalTo('HTTP/1.1 404 '));86 $this->response->setStatusCode(404, 'Not Found'); 87 $this->response->expects($this->once())->method('header')->with($this->equalTo('HTTP/1.1 404 Not Found')); 88 88 $this->response->send(); 89 89 $this->response->clear();
