ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Slim_Http_Response Class Reference
+ Collaboration diagram for Slim_Http_Response:

Public Member Functions

 __construct (Slim_Http_Request $req)
 Constructor.
 httpVersion ($version=null)
 Set and/or get the HTTP response version.
 status ($status=null)
 Set and/or get the HTTP response status code.
 headers ()
 Get HTTP response headers.
 header ($key, $value=null)
 Get and/or set an HTTP response header.
 body ($body=null)
 Set the HTTP response body.
 write ($body)
 Append the HTTP response body.
 setCookieJar (Slim_Http_CookieJar $cookieJar)
 Set cookie jar.
 getCookieJar ()
 Get cookie jar.
 finalize ()
 Finalize response headers before response is sent.
 canHaveBody ()
 Can this HTTP response have a body?
 send ()
 Send HTTP response.

Static Public Member Functions

static getMessageForCode ($status)
 Get message for HTTP status code.

Protected Member Functions

 sendHeaders ()
 Send headers for HTTP response.

Protected Attributes

 $request
 $httpVersion = '1.1'
 $status = 200
 $headers = array()
 $body = ''
 $length = 0
 $cookieJar

Static Protected Attributes

static $messages

Detailed Description

Definition at line 49 of file Response.php.

Constructor & Destructor Documentation

Slim_Http_Response::__construct ( Slim_Http_Request  $req)

Constructor.

Definition at line 143 of file Response.php.

References header().

{
$this->request = $req;
$this->header('Content-Type', 'text/html');
}

+ Here is the call graph for this function:

Member Function Documentation

int Length of HTTP response Slim_Http_Response::body (   $body = null)

Set the HTTP response body.

Parameters
string$bodyThe new HTTP response body
Returns
string The new HTTP response body

Definition at line 208 of file Response.php.

References $body, and write().

Referenced by finalize(), and write().

{
if ( !is_null($body) ) {
$this->body = '';
$this->length = 0;
$this->write($body);
}
return $this->body;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Response::canHaveBody ( )

Can this HTTP response have a body?

Returns
bool

Definition at line 270 of file Response.php.

References status().

Referenced by send().

{
return ( $this->status < 100 || $this->status >= 200 ) && $this->status != 204 && $this->status != 304;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Response::finalize ( )

Finalize response headers before response is sent.

Returns
void

Definition at line 251 of file Response.php.

References body(), headers(), and status().

Referenced by sendHeaders().

{
if ( in_array($this->status, array(204, 304)) ) {
$this->body('');
unset($this->headers['Content-Type']);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Response::getCookieJar ( )

Get cookie jar.

Returns
Slim_Http_CookieJar

Definition at line 243 of file Response.php.

References $cookieJar.

Referenced by sendHeaders().

{
}

+ Here is the caller graph for this function:

static Slim_Http_Response::getMessageForCode (   $status)
static

Get message for HTTP status code.

Returns
string|null

Definition at line 262 of file Response.php.

References $messages, and $status.

{
return isset(self::$messages[$status]) ? self::$messages[$status] : null;
}
Slim_Http_Response::header (   $key,
  $value = null 
)

Get and/or set an HTTP response header.

Parameters
string$keyThe header name
string$valueThe header value
Returns
string|null The header value, or NULL if header not set

Definition at line 196 of file Response.php.

References headers().

Referenced by __construct(), sendHeaders(), and write().

{
if ( !is_null($value) ) {
$this->headers[$key] = $value;
}
return isset($this->headers[$key]) ? $this->headers[$key] : null;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

array Key value array of HTTP response Slim_Http_Response::headers ( )

Get HTTP response headers.

Returns
array

Definition at line 186 of file Response.php.

References $headers.

Referenced by finalize(), header(), and sendHeaders().

{
}

+ Here is the caller graph for this function:

Slim_Http_Response::httpVersion (   $version = null)

Set and/or get the HTTP response version.

Parameters
string$version
Returns
void
Exceptions
InvalidArgumentExceptionIf argument is not a valid HTTP version

Definition at line 154 of file Response.php.

References $httpVersion.

Referenced by sendHeaders().

{
if ( $version ) {
$version = (string)$version;
if ( $version === '1.0' || $version === '1.1' ) {
$this->httpVersion = $version;
} else {
throw new InvalidArgumentException('Invalid HTTP version in Response object');
}
}
}

+ Here is the caller graph for this function:

Slim_Http_Response::send ( )

Send HTTP response.

This method will set Response headers, set Response cookies, and echo the Response body to the current output buffer.

Returns
void

Definition at line 317 of file Response.php.

References $body, canHaveBody(), and sendHeaders().

{
if ( !headers_sent() ) {
$this->sendHeaders();
}
if ( $this->canHaveBody() && $this->request->isHead() === false ) {
}
}

+ Here is the call graph for this function:

Slim_Http_Response::sendHeaders ( )
protected

Send headers for HTTP response.

Returns
void

Definition at line 278 of file Response.php.

References finalize(), getCookieJar(), header(), headers(), httpVersion(), and status().

Referenced by send().

{
//Finalize response
$this->finalize();
if ( substr(PHP_SAPI, 0, 3) === 'cgi') {
//Send Status header if running with fastcgi
header('Status: ' . self::getMessageForCode($this->status()));
} else {
//Else send HTTP message
header(sprintf('HTTP/%s %s', $this->httpVersion, self::getMessageForCode($this->status())));
}
//Send headers
foreach ( $this->headers() as $name => $value ) {
header("$name: $value");
}
//Send cookies
foreach ( $this->getCookieJar()->getResponseCookies() as $name => $cookie ) {
/* httponly option is only available for PHP version >= 5.2 */
if ( version_compare(PHP_VERSION, '5.2.0', '>=') ) {
setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpires(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
} else {
setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpires(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure());
}
}
//Flush all output to client
flush();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Response::setCookieJar ( Slim_Http_CookieJar  $cookieJar)

Set cookie jar.

Parameters
Slim_Http_CookieJar$cookieJar
Returns
void

Definition at line 235 of file Response.php.

References $cookieJar.

{
$this->cookieJar = $cookieJar;
}
Slim_Http_Response::status (   $status = null)

Set and/or get the HTTP response status code.

Parameters
int$status
Returns
int
Exceptions
InvalidArgumentExceptionIf argument is not a valid HTTP status code

Definition at line 172 of file Response.php.

References $messages, and $status.

Referenced by canHaveBody(), finalize(), and sendHeaders().

{
if ( !is_null($status) ) {
if ( !in_array(intval($status), array_keys(self::$messages)) ) {
throw new InvalidArgumentException('Cannot set Response status. Provided status code "' . $status . '" is not a valid HTTP response code.');
}
$this->status = intval($status);
}
return $this->status;
}

+ Here is the caller graph for this function:

Slim_Http_Response::write (   $body)

Append the HTTP response body.

Parameters
string$bodyContent to append to the current HTTP response body
Returns
string The updated HTTP response body

Definition at line 222 of file Response.php.

References $body, body(), and header().

Referenced by body().

{
$body = (string)$body;
$this->length += strlen($body);
$this->body .= $body;
$this->header('Content-Length', $this->length);
return $body;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

Slim_Http_Response::$body = ''
protected

Definition at line 74 of file Response.php.

Referenced by body(), send(), and write().

Slim_Http_Response::$cookieJar
protected

Definition at line 138 of file Response.php.

Referenced by getCookieJar(), and setCookieJar().

Slim_Http_Response::$headers = array()
protected

Definition at line 69 of file Response.php.

Referenced by headers().

Slim_Http_Response::$httpVersion = '1.1'
protected

Definition at line 59 of file Response.php.

Referenced by httpVersion().

Slim_Http_Response::$length = 0
protected

Definition at line 79 of file Response.php.

Slim_Http_Response::$messages
staticprotected

Definition at line 84 of file Response.php.

Slim_Http_Response::$request
protected

Definition at line 54 of file Response.php.

Slim_Http_Response::$status = 200
protected

Definition at line 64 of file Response.php.

Referenced by getMessageForCode(), and status().


The documentation for this class was generated from the following file: