ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Slim_Http_Response Class Reference
+ Collaboration diagram for Slim_Http_Response:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 sendHeaders ()
 Send headers for HTTP response. More...
 

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

◆ __construct()

Slim_Http_Response::__construct ( Slim_Http_Request  $req)

Constructor.

Definition at line 143 of file Response.php.

References header().

143  {
144  $this->request = $req;
145  $this->header('Content-Type', 'text/html');
146  }
header( $key, $value=null)
Get and/or set an HTTP response header.
Definition: Response.php:196
+ Here is the call graph for this function:

Member Function Documentation

◆ body()

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().

208  {
209  if ( !is_null($body) ) {
210  $this->body = '';
211  $this->length = 0;
212  $this->write($body);
213  }
214  return $this->body;
215  }
write( $body)
Append the HTTP response body.
Definition: Response.php:222
body( $body=null)
Set the HTTP response body.
Definition: Response.php:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canHaveBody()

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().

270  {
271  return ( $this->status < 100 || $this->status >= 200 ) && $this->status != 204 && $this->status != 304;
272  }
status( $status=null)
Set and/or get the HTTP response status code.
Definition: Response.php:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalize()

Slim_Http_Response::finalize ( )

Finalize response headers before response is sent.

Returns
void

Definition at line 251 of file Response.php.

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

Referenced by sendHeaders().

251  {
252  if ( in_array($this->status, array(204, 304)) ) {
253  $this->body('');
254  unset($this->headers['Content-Type']);
255  }
256  }
status( $status=null)
Set and/or get the HTTP response status code.
Definition: Response.php:172
body( $body=null)
Set the HTTP response body.
Definition: Response.php:208
Create styles array
The data for the language used.
headers()
Get HTTP response headers.
Definition: Response.php:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCookieJar()

Slim_Http_Response::getCookieJar ( )

Get cookie jar.

Returns
Slim_Http_CookieJar

Definition at line 243 of file Response.php.

References $cookieJar.

Referenced by sendHeaders().

243  {
244  return $this->cookieJar;
245  }
+ Here is the caller graph for this function:

◆ getMessageForCode()

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.

262  {
263  return isset(self::$messages[$status]) ? self::$messages[$status] : null;
264  }
$messages
Definition: en-x-test.php:7

◆ header()

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().

196  {
197  if ( !is_null($value) ) {
198  $this->headers[$key] = $value;
199  }
200  return isset($this->headers[$key]) ? $this->headers[$key] : null;
201  }
headers()
Get HTTP response headers.
Definition: Response.php:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ headers()

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().

186  {
187  return $this->headers;
188  }
+ Here is the caller graph for this function:

◆ httpVersion()

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, $version, and string.

Referenced by sendHeaders().

154  {
155  if ( $version ) {
157  if ( $version === '1.0' || $version === '1.1' ) {
158  $this->httpVersion = $version;
159  } else {
160  throw new InvalidArgumentException('Invalid HTTP version in Response object');
161  }
162  }
163  return $this->httpVersion;
164  }
httpVersion( $version=null)
Set and/or get the HTTP response version.
Definition: Response.php:154
Add rich text string
The name of the decorator.
+ Here is the caller graph for this function:

◆ send()

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().

317  {
318  if ( !headers_sent() ) {
319  $this->sendHeaders();
320  }
321  if ( $this->canHaveBody() && $this->request->isHead() === false ) {
323  }
324  }
canHaveBody()
Can this HTTP response have a body?
Definition: Response.php:270
sendHeaders()
Send headers for HTTP response.
Definition: Response.php:278
+ Here is the call graph for this function:

◆ sendHeaders()

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().

278  {
279  //Finalize response
280  $this->finalize();
281 
282  if ( substr(PHP_SAPI, 0, 3) === 'cgi') {
283  //Send Status header if running with fastcgi
284  header('Status: ' . self::getMessageForCode($this->status()));
285  } else {
286  //Else send HTTP message
287  header(sprintf('HTTP/%s %s', $this->httpVersion, self::getMessageForCode($this->status())));
288  }
289 
290  //Send headers
291  foreach ( $this->headers() as $name => $value ) {
292  header("$name: $value");
293  }
294 
295  //Send cookies
296  foreach ( $this->getCookieJar()->getResponseCookies() as $name => $cookie ) {
297  /* httponly option is only available for PHP version >= 5.2 */
298  if ( version_compare(PHP_VERSION, '5.2.0', '>=') ) {
299  setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpires(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
300  } else {
301  setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpires(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure());
302  }
303  }
304 
305  //Flush all output to client
306  flush();
307  }
status( $status=null)
Set and/or get the HTTP response status code.
Definition: Response.php:172
getCookieJar()
Get cookie jar.
Definition: Response.php:243
httpVersion( $version=null)
Set and/or get the HTTP response version.
Definition: Response.php:154
header( $key, $value=null)
Get and/or set an HTTP response header.
Definition: Response.php:196
finalize()
Finalize response headers before response is sent.
Definition: Response.php:251
headers()
Get HTTP response headers.
Definition: Response.php:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCookieJar()

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.

235  {
236  $this->cookieJar = $cookieJar;
237  }

◆ status()

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().

172  {
173  if ( !is_null($status) ) {
174  if ( !in_array(intval($status), array_keys(self::$messages)) ) {
175  throw new InvalidArgumentException('Cannot set Response status. Provided status code "' . $status . '" is not a valid HTTP response code.');
176  }
177  $this->status = intval($status);
178  }
179  return $this->status;
180  }
status( $status=null)
Set and/or get the HTTP response status code.
Definition: Response.php:172
$messages
Definition: en-x-test.php:7
+ Here is the caller graph for this function:

◆ write()

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(), header(), and string.

Referenced by body().

222  {
223  $body = (string)$body;
224  $this->length += strlen($body);
225  $this->body .= $body;
226  $this->header('Content-Length', $this->length);
227  return $body;
228  }
Add rich text string
The name of the decorator.
body( $body=null)
Set the HTTP response body.
Definition: Response.php:208
header( $key, $value=null)
Get and/or set an HTTP response header.
Definition: Response.php:196
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $body

Slim_Http_Response::$body = ''
protected

Definition at line 74 of file Response.php.

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

◆ $cookieJar

Slim_Http_Response::$cookieJar
protected

Definition at line 138 of file Response.php.

Referenced by getCookieJar(), and setCookieJar().

◆ $headers

Slim_Http_Response::$headers = array()
protected

Definition at line 69 of file Response.php.

Referenced by headers().

◆ $httpVersion

Slim_Http_Response::$httpVersion = '1.1'
protected

Definition at line 59 of file Response.php.

Referenced by httpVersion().

◆ $length

Slim_Http_Response::$length = 0
protected

Definition at line 79 of file Response.php.

◆ $messages

Slim_Http_Response::$messages
staticprotected

Definition at line 84 of file Response.php.

◆ $request

Slim_Http_Response::$request
protected

Definition at line 54 of file Response.php.

◆ $status

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: