Update Request and Response
Add constructor for Request to provide URI and method on instantiation. Add success property and getSuccess() method Response. Closes #1
This commit is contained in:
parent
b0133d9173
commit
972f8e9c26
|
|
@ -74,6 +74,23 @@ class Request extends Message
|
||||||
*/
|
*/
|
||||||
static protected $theRequest;
|
static protected $theRequest;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Request instance.
|
||||||
|
*
|
||||||
|
* @param string|null $uri
|
||||||
|
* @param string $method
|
||||||
|
*/
|
||||||
|
public function __construct($uri = null, $method = 'GET')
|
||||||
|
{
|
||||||
|
if (!is_null($uri)) {
|
||||||
|
$this->setUri($uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->method = $method;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Accessors
|
// Accessors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ use \InvalidArgumentException;
|
||||||
* @property string reasonPhrase Text explanation of status code.
|
* @property string reasonPhrase Text explanation of status code.
|
||||||
* @property int statusCode HTTP status code
|
* @property int statusCode HTTP status code
|
||||||
* @property-read string statusLine HTTP status line, e.g. "HTTP/1.1 200 OK"
|
* @property-read string statusLine HTTP status line, e.g. "HTTP/1.1 200 OK"
|
||||||
|
* @property-read bool success True if the status code is 2xx
|
||||||
*/
|
*/
|
||||||
class Response extends Message
|
class Response extends Message
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text explanation of the HTTP Status Code. You only need to set this if
|
* Text explanation of the HTTP Status Code. You only need to set this if
|
||||||
* you are using nonstandard status codes. Otherwise, the instance will
|
* you are using nonstandard status codes. Otherwise, the instance will
|
||||||
|
|
@ -94,6 +94,16 @@ class Response extends Message
|
||||||
return $this->reasonPhrase;
|
return $this->reasonPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the status code is in the 2xx range.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getSuccess()
|
||||||
|
{
|
||||||
|
return $this->statusCode >= 200 && $this->statusCode < 300;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign an explaination for the status code. Not normally needed.
|
* Assign an explaination for the status code. Not normally needed.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue