Changeset 1478

Show
Ignore:
Timestamp:
03/30/08 16:34:02 (5 months ago)
Author:
mikey
Message:

changed param order: version is more likely to be set then sapi
added support reasonPhrase in status codes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/response/stubBaseResponse.php

    r1471 r1478  
    3434    protected $version; 
    3535    /** 
    36      * the status code to be send 
     36     * status code to be send 
    3737     * 
    3838     * @var  int 
    3939     */ 
    40     protected $statusCode = null; 
     40    protected $statusCode; 
     41    /** 
     42     * status message to be send 
     43     * 
     44     * @var  string 
     45     */ 
     46    protected $reasonPhrase; 
    4147    /** 
    4248     * list of headers for this response 
     
    4450     * @var  array<string,string> 
    4551     */ 
    46     protected $headers    = array(); 
     52    protected $headers       = array(); 
    4753    /** 
    4854     * list of cookies for this response 
     
    5056     * @var  array<string,stubCookie> 
    5157     */ 
    52     protected $cookies    = array(); 
     58    protected $cookies       = array(); 
    5359    /** 
    5460     * data to send as body of response 
     
    5662     * @var  string 
    5763     */ 
    58     protected $data       = null
     64    protected $data
    5965 
    6066    /** 
    6167     * constructor 
    6268     * 
     69     * @param  string  $version  optional  http version 
    6370     * @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     { 
     71     */ 
     72    public function __construct($version = '1.1', $sapi = PHP_SAPI) 
     73    { 
     74        $this->version = $version; 
    6875        $this->sapi    = $sapi; 
    69         $this->version = $version; 
    7076    } 
    7177 
     
    7581    public function clear() 
    7682    { 
    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; 
    8188    } 
    8289 
     
    109116     * should be send. 
    110117     * 
    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; 
    116125    } 
    117126 
     
    206215        if (null !== $this->statusCode) { 
    207216            if ('cgi' === $this->sapi) { 
    208                 $this->header('Status: ' . $this->statusCode); 
     217                $this->header('Status: ' . $this->statusCode . ' ' . $this->reasonPhrase); 
    209218            } else { 
    210                 $this->header('HTTP/' . $this->version . ' ' . $this->statusCode); 
     219                $this->header('HTTP/' . $this->version . ' ' . $this->statusCode . ' ' . $this->reasonPhrase); 
    211220            } 
    212221        } 
  • trunk/src/main/php/net/stubbles/ipo/response/stubResponse.php

    r1471 r1478  
    4646     * should be send. 
    4747     * 
    48      * @param  int  $statusCode 
     48     * @param  int     $statusCode 
     49     * @param  string  $reasonPhrase  optional 
    4950     */ 
    50     public function setStatusCode($statusCode); 
     51    public function setStatusCode($statusCode, $reasonPhrase = null); 
    5152 
    5253    /** 
  • trunk/src/test/php/net/stubbles/ipo/response/stubBaseResponseTestCase.php

    r1471 r1478  
    4444        $this->assertEquals('1.0', $this->response->getVersion()); 
    4545         
    46         $response = new stubBaseResponse(PHP_SAPI, '1.0'); 
     46        $response = new stubBaseResponse('1.0'); 
    4747        $this->assertEquals('1.0', $response->getVersion()); 
    4848    } 
     
    6767    public function statusCodeInCgiSapi() 
    6868    { 
    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')); 
    7070        $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')); 
    7373        $this->response->send(); 
    7474        $this->response->clear(); 
     
    8484    { 
    8585        $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')); 
    8888        $this->response->send(); 
    8989        $this->response->clear();