The request and response API's

Request

/**
 * Creates the request object
 *
 * @param string $method
 * @param string $url
 * @param array $headers
 * @param resource $body
 */
public function __construct($method = null, $url = null, array $headers = null, $body = null);

/**
 * Returns the current HTTP method
 *
 * @return string
 */
function getMethod();

/**
 * Sets the HTTP method
 *
 * @param string $method
 * @return void
 */
function setMethod($method);

/**
 * Returns the request url.
 *
 * @return string
 */
function getUrl();

/**
 * Sets the request url.
 *
 * @param string $url
 * @return void
 */
function setUrl($url);

/**
 * Returns the absolute url.
 *
 * @return string
 */
function getAbsoluteUrl();

/**
 * Sets the absolute url.
 *
 * @param string $url
 * @return void
 */
function setAbsoluteUrl($url);

/**
 * Returns the current base url.
 *
 * @return string
 */
function getBaseUrl();

/**
 * Sets a base url.
 *
 * This url is used for relative path calculations.
 *
 * The base url should default to /
 *
 * @param string $url
 * @return void
 */
function setBaseUrl($url);

/**
 * Returns the relative path.
 *
 * This is being calculated using the base url. This path will not start
 * with a slash, so it will always return something like
 * 'example/path.html'.
 *
 * If the full path is equal to the base url, this method will return an
 * empty string.
 *
 * This method will also urldecode the path, and if the url was incoded as
 * ISO-8859-1, it will convert it to UTF-8.
 *
 * If the path is outside of the base url, a LogicException will be thrown.
 *
 * @return string
 */
function getPath();

/**
 * Returns the list of query parameters.
 *
 * This is equivalent to PHP's $_GET superglobal.
 *
 * @return array
 */
function getQueryParameters();

/**
 * Returns the POST data.
 *
 * This is equivalent to PHP's $_POST superglobal.
 *
 * @return array
 */
function getPostData();

/**
 * Sets the post data.
 *
 * This is equivalent to PHP's $_POST superglobal.
 *
 * This would not have been needed, if POST data was accessible as
 * php://input, but unfortunately we need to special case it.
 *
 * @param array $postData
 * @return void
 */
function setPostData(array $postData);

/**
 * Returns an item from the _SERVER array.
 *
 * If the value does not exist in the array, null is returned.
 *
 * @param string $valueName
 * @return string|null
 */
function getRawServerValue($valueName);

/**
 * Sets the _SERVER array.
 *
 * @param array $data
 * @return void
 */
function setRawServerData(array $data);

/**
 * Returns the body as a readable stream resource.
 *
 * Note that the stream may not be rewindable, and therefore may only be
 * read once.
 *
 * @return resource
 */
function getBodyAsStream();

/**
 * Returns the body as a string.
 *
 * Note that because the underlying data may be based on a stream, this
 * method could only work correctly the first time.
 *
 * @return string
 */
function getBodyAsString();

/**
 * Returns the message body, as it's internal representation.
 *
 * This could be either a string or a stream.
 *
 * @return resource|string
 */
function getBody();

/**
 * Updates the body resource with a new stream.
 *
 * @param resource $body
 * @return void
 */
function setBody($body);

/**
 * Returns all the HTTP headers as an array.
 *
 * Every header is returned as an array, with one or more values.
 *
 * @return array
 */
function getHeaders();

/**
 * Will return true or false, depending on if a http header exists.
 *
 * @param string $name
 * @return bool
 */
function hasHeader($name);

/**
 * Returns a specific HTTP header, based on it's name.
 *
 * The name must be treated as case-insensitive.
 * If the header does not exist, this method must return null.
 *
 * If a header appeared more than once in a http request, this method will
 * concatenate all the values with a comma.
 *
 * Note that this not make sense for all headers. Some, such as
 * `Set-Cookie` cannot be logically combined with a comma. In those cases
 * you *should* use getHeaderAsArray().
 *
 * @param string $name
 * @return string|null
 */
function getHeader($name);

/**
 * Returns a HTTP header as an array.
 *
 * For every time the http header appeared in the request or response, an
 * item will appear in the array.
 *
 * If the header did not exists, this method will return an empty array.
 *
 * @param string $name
 * @return string[]
 */
function getHeaderAsArray($name);

/**
 * Updates a HTTP header.
 *
 * The case-sensitity of the name value must be retained as-is.
 *
 * If the header already existed, it will be overwritten.
 *
 * @param string $name
 * @param string|string[] $value
 * @return void
 */
function setHeader($name, $value);

/**
 * Sets a new set of HTTP headers.
 *
 * The headers array should contain headernames for keys, and their value
 * should be specified as either a string or an array.
 *
 * Any header that already existed will be overwritten.
 *
 * @param array $headers
 * @return void
 */
function setHeaders(array $headers);

/**
 * Adds a HTTP header.
 *
 * This method will not overwrite any existing HTTP header, but instead add
 * another value. Individual values can be retrieved with
 * getHeadersAsArray.
 *
 * @param string $name
 * @param string $value
 * @return void
 */
function addHeader($name, $value);

/**
 * Adds a new set of HTTP headers.
 *
 * Any existing headers will not be overwritten.
 *
 * @param array $headers
 * @return void
 */
function addHeaders(array $headers);

/**
 * Removes a HTTP header.
 *
 * The specified header name must be treated as case-insenstive.
 * This method should return true if the header was successfully deleted,
 * and false if the header did not exist.
 *
 * @return bool
 */
function removeHeader($name);

/**
 * Sets the HTTP version.
 *
 * Should be 1.0 or 1.1.
 *
 * @param string $version
 * @return void
 */
function setHttpVersion($version);

/**
 * Returns the HTTP version.
 *
 * @return string
 */
function getHttpVersion();

Response

/**
 * Returns the current HTTP status.
 *
 * This is the status-code as well as the human readable string.
 *
 * @return string
 */
function getStatus();

/**
 * Sets the HTTP status code.
 *
 * This can be either the full HTTP status code with human readable string,
 * for example: "403 I can't let you do that, Dave".
 *
 * Or just the code, in which case the appropriate default message will be
 * added.
 *
 * @param string|int $status
 * @throws \InvalidArgumentExeption
 * @return void
 */
function setStatus($status);

/**
 * Returns the body as a readable stream resource.
 *
 * Note that the stream may not be rewindable, and therefore may only be
 * read once.
 *
 * @return resource
 */
function getBodyAsStream();

/**
 * Returns the body as a string.
 *
 * Note that because the underlying data may be based on a stream, this
 * method could only work correctly the first time.
 *
 * @return string
 */
function getBodyAsString();

/**
 * Returns the message body, as it's internal representation.
 *
 * This could be either a string or a stream.
 *
 * @return resource|string
 */
function getBody();


/**
 * Updates the body resource with a new stream.
 *
 * @param resource $body
 * @return void
 */
function setBody($body);

/**
 * Returns the body as a readable stream resource.
 *
 * Note that the stream may not be rewindable, and therefore may only be
 * read once.
 *
 * @return resource
 */
function getBodyAsStream();

/**
 * Returns the body as a string.
 *
 * Note that because the underlying data may be based on a stream, this
 * method could only work correctly the first time.
 *
 * @return string
 */
function getBodyAsString();

/**
 * Returns the message body, as it's internal representation.
 *
 * This could be either a string or a stream.
 *
 * @return resource|string
 */
function getBody();

/**
 * Updates the body resource with a new stream.
 *
 * @param resource $body
 * @return void
 */
function setBody($body);

/**
 * Returns all the HTTP headers as an array.
 *
 * Every header is returned as an array, with one or more values.
 *
 * @return array
 */
function getHeaders();

/**
 * Will return true or false, depending on if a http header exists.
 *
 * @param string $name
 * @return bool
 */
function hasHeader($name);

/**
 * Returns a specific HTTP header, based on it's name.
 *
 * The name must be treated as case-insensitive.
 * If the header does not exist, this method must return null.
 *
 * If a header appeared more than once in a http request, this method will
 * concatenate all the values with a comma.
 *
 * Note that this not make sense for all headers. Some, such as
 * `Set-Cookie` cannot be logically combined with a comma. In those cases
 * you *should* use getHeaderAsArray().
 *
 * @param string $name
 * @return string|null
 */
function getHeader($name);

/**
 * Returns a HTTP header as an array.
 *
 * For every time the http header appeared in the request or response, an
 * item will appear in the array.
 *
 * If the header did not exists, this method will return an empty array.
 *
 * @param string $name
 * @return string[]
 */
function getHeaderAsArray($name);

/**
 * Updates a HTTP header.
 *
 * The case-sensitity of the name value must be retained as-is.
 *
 * If the header already existed, it will be overwritten.
 *
 * @param string $name
 * @param string|string[] $value
 * @return void
 */
function setHeader($name, $value);

/**
 * Sets a new set of HTTP headers.
 *
 * The headers array should contain headernames for keys, and their value
 * should be specified as either a string or an array.
 *
 * Any header that already existed will be overwritten.
 *
 * @param array $headers
 * @return void
 */
function setHeaders(array $headers);

/**
 * Adds a HTTP header.
 *
 * This method will not overwrite any existing HTTP header, but instead add
 * another value. Individual values can be retrieved with
 * getHeadersAsArray.
 *
 * @param string $name
 * @param string $value
 * @return void
 */
function addHeader($name, $value);

/**
 * Adds a new set of HTTP headers.
 *
 * Any existing headers will not be overwritten.
 *
 * @param array $headers
 * @return void
 */
function addHeaders(array $headers);

/**
 * Removes a HTTP header.
 *
 * The specified header name must be treated as case-insenstive.
 * This method should return true if the header was successfully deleted,
 * and false if the header did not exist.
 *
 * @return bool
 */
function removeHeader($name);

/**
 * Sets the HTTP version.
 *
 * Should be 1.0 or 1.1.
 *
 * @param string $version
 * @return void
 */
function setHttpVersion($version);

/**
 * Returns the HTTP version.
 *
 * @return string
 */
function getHttpVersion();

Comments