ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Slim_Http_Request Class Reference
+ Collaboration diagram for Slim_Http_Request:

Public Member Functions

 __construct ()
 Constructor.
 isGet ()
 Is this a GET request?
 isPost ()
 Is this a POST request?
 isPut ()
 Is this a PUT request?
 isDelete ()
 Is this a DELETE request?
 isHead ()
 Is this a HEAD request?
 isOptions ()
 Is this a OPTIONS request?
 isAjax ()
 Is this a XHR request?
 params ($key)
 Fetch a PUT|POST|GET parameter value.
 get ($key=null)
 Fetch GET parameter(s)
 post ($key=null)
 Fetch POST parameter(s)
 put ($key=null)
 Fetch PUT parameter(s)
 cookies ($key=null)
 Fetch COOKIE value(s)
 headers ($key=null)
 Get HTTP request header.
 getBody ()
 Get HTTP request body.
 getMethod ()
 Get HTTP method.
 getContentType ()
 Get HTTP request content type.
 getResourceUri ()
 Get HTTP request resource URI.
 getRootUri ()
 Get HTTP request root URI.

Static Public Member Functions

static stripSlashesIfMagicQuotes ($rawData)
 Strip slashes from string or array of strings.

Data Fields

const METHOD_HEAD = 'HEAD'
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
const METHOD_PUT = 'PUT'
const METHOD_DELETE = 'DELETE'
const METHOD_OPTIONS = 'OPTIONS'
const METHOD_OVERRIDE = '_METHOD'

Protected Member Functions

 arrayOrArrayValue (array &$array, $key=null)
 Fetch array or array value.
 arrayValueForKey (array &$array, $key)
 Fetch value from array.
 loadPutParameters ()
 Get PUT parameters.
 loadHttpHeaders ()
 Get HTTP request headers.
 convertHttpHeaderName ($name)
 Convert HTTP header name.
 checkForHttpMethodOverride ()
 Check for HTTP request method override.

Protected Attributes

 $method
 $headers
 $additionalHeaders = array('content-type', 'content-length', 'php-auth-user', 'php-auth-pw', 'auth-type', 'x-requested-with')
 $cookies
 $get
 $post
 $put
 $body
 $contentType
 $resource
 $root

Detailed Description

Definition at line 48 of file Request.php.

Constructor & Destructor Documentation

Slim_Http_Request::__construct ( )

Constructor.

Definition at line 121 of file Request.php.

References $_COOKIE, $_GET, $_POST, checkForHttpMethodOverride(), cookies(), Slim_Http_Uri\getBaseUri(), Slim_Http_Uri\getUri(), headers(), loadHttpHeaders(), loadPutParameters(), post(), put(), and stripSlashesIfMagicQuotes().

{
$this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
$this->headers = $this->loadHttpHeaders();
$this->body = @file_get_contents('php://input');
$this->root = Slim_Http_Uri::getBaseUri(true);
$this->resource = Slim_Http_Uri::getUri(true);
}

+ Here is the call graph for this function:

Member Function Documentation

Slim_Http_Request::arrayOrArrayValue ( array &  $array,
  $key = null 
)
protected

Fetch array or array value.

Parameters
array$array
string$key
Returns
array|mixed Array if key is null, else array value

Definition at line 319 of file Request.php.

References arrayValueForKey().

Referenced by cookies(), get(), headers(), post(), and put().

{
return is_null($key) ? $array : $this->arrayValueForKey($array, $key);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::arrayValueForKey ( array &  $array,
  $key 
)
protected

Fetch value from array.

Returns
mixed|null

Definition at line 327 of file Request.php.

Referenced by arrayOrArrayValue().

{
return isset($array[(string)$key]) ? $array[(string)$key] : null;
}

+ Here is the caller graph for this function:

Slim_Http_Request::checkForHttpMethodOverride ( )
protected

Check for HTTP request method override.

Because traditional web browsers do not support PUT and DELETE HTTP methods, we use a hidden form input field to mimic PUT and DELETE requests. We check for this override here.

Returns
void

Definition at line 395 of file Request.php.

References $post, isPut(), METHOD_OVERRIDE, post(), and put().

Referenced by __construct().

{
if ( isset($this->post[self::METHOD_OVERRIDE]) ) {
$this->method = $this->post[self::METHOD_OVERRIDE];
unset($this->post[self::METHOD_OVERRIDE]);
if ( $this->isPut() ) {
$this->put = $this->post;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::convertHttpHeaderName (   $name)
protected

Convert HTTP header name.

Returns
string

Definition at line 382 of file Request.php.

Referenced by headers(), and loadHttpHeaders().

{
return str_replace('_', '-', strtolower($name));
}

+ Here is the caller graph for this function:

Slim_Http_Request::cookies (   $key = null)

Fetch COOKIE value(s)

Parameters
string$keyThe cookie name
Returns
array|string|null All parameters, parameter value if $key and parameter exists, or NULL if $key and parameter does not exist.

Definition at line 249 of file Request.php.

References arrayOrArrayValue().

Referenced by __construct().

{
return $this->arrayOrArrayValue($this->cookies, $key);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::get (   $key = null)

Fetch GET parameter(s)

Parameters
string$keyName of parameter
Returns
array|string|null All parameters, parameter value if $key and parameter exists, or NULL if $key and parameter does not exist.

Definition at line 216 of file Request.php.

References arrayOrArrayValue().

{
return $this->arrayOrArrayValue($this->get, $key);
}

+ Here is the call graph for this function:

Slim_Http_Request::getBody ( )

Get HTTP request body.

Returns
string|false String, or FALSE if body could not be read

Definition at line 268 of file Request.php.

References $body.

{
return $this->body;
}
Slim_Http_Request::getContentType ( )

Get HTTP request content type.

Returns
string

Definition at line 284 of file Request.php.

References $contentType, and headers().

Referenced by loadPutParameters().

{
if ( !isset($this->contentType) ) {
$contentType = 'application/x-www-form-urlencoded';
$header = $this->headers('CONTENT_TYPE');
if ( !is_null($header) ) {
$headerParts = preg_split('/\s*;\s*/', $header);
$contentType = $headerParts[0];
}
$this->contentType = $contentType;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::getMethod ( )

Get HTTP method.

Returns
string

Definition at line 276 of file Request.php.

References $method.

{
return $this->method;
}
Slim_Http_Request::getResourceUri ( )

Get HTTP request resource URI.

Returns
string

Definition at line 301 of file Request.php.

References $resource.

{
}
Slim_Http_Request::getRootUri ( )

Get HTTP request root URI.

Returns
string

Definition at line 309 of file Request.php.

References $root.

{
return $this->root;
}
array Key value array of HTTP request Slim_Http_Request::headers (   $key = null)

Get HTTP request header.

Parameters
string$keyThe header name
Returns
array|string|null All parameters, parameter value if $key and parameter exists, or NULL if $key and parameter does not exist.

Definition at line 260 of file Request.php.

References arrayOrArrayValue(), and convertHttpHeaderName().

Referenced by __construct(), getContentType(), and isAjax().

{
return is_null($key) ? $this->headers : $this->arrayOrArrayValue($this->headers, $this->convertHttpHeaderName($key));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::isAjax ( )

Is this a XHR request?

Returns
bool

Definition at line 186 of file Request.php.

References headers(), and params().

{
return ( $this->params('isajax') || $this->headers('X_REQUESTED_WITH') === 'XMLHttpRequest' );
}

+ Here is the call graph for this function:

Slim_Http_Request::isDelete ( )

Is this a DELETE request?

Returns
bool

Definition at line 162 of file Request.php.

References METHOD_DELETE.

{
return $this->method === self::METHOD_DELETE;
}
Slim_Http_Request::isGet ( )

Is this a GET request?

Returns
bool

Definition at line 138 of file Request.php.

References METHOD_GET.

{
return $this->method === self::METHOD_GET;
}
Slim_Http_Request::isHead ( )

Is this a HEAD request?

Returns
bool

Definition at line 170 of file Request.php.

References METHOD_HEAD.

{
return $this->method === self::METHOD_HEAD;
}
Slim_Http_Request::isOptions ( )

Is this a OPTIONS request?

Returns
bool

Definition at line 178 of file Request.php.

References METHOD_OPTIONS.

{
return $this->method === self::METHOD_OPTIONS;
}
Slim_Http_Request::isPost ( )

Is this a POST request?

Returns
bool

Definition at line 146 of file Request.php.

References METHOD_POST.

{
return $this->method === self::METHOD_POST;
}
Slim_Http_Request::isPut ( )

Is this a PUT request?

Returns
bool

Definition at line 154 of file Request.php.

References METHOD_PUT.

Referenced by checkForHttpMethodOverride().

{
return $this->method === self::METHOD_PUT;
}

+ Here is the caller graph for this function:

Slim_Http_Request::loadHttpHeaders ( )
protected

Get HTTP request headers.

Returns
array Key-value array of HTTP request headers

Definition at line 366 of file Request.php.

References $headers, and convertHttpHeaderName().

Referenced by __construct().

{
$headers = array();
foreach ( $_SERVER as $key => $value ) {
$key = $this->convertHttpHeaderName($key);
if ( strpos($key, 'http-') === 0 || in_array($key, $this->additionalHeaders) ) {
$name = str_replace('http-', '', $key);
$headers[$name] = $value;
}
}
return $headers;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::loadPutParameters ( )
protected

Get PUT parameters.

Returns
array Key-value array of HTTP request PUT parameters

Definition at line 348 of file Request.php.

References getContentType().

Referenced by __construct().

{
if ( $this->getContentType() === 'application/x-www-form-urlencoded' ) {
$input = is_string($this->body) ? $this->body : '';
if ( function_exists('mb_parse_str') ) {
mb_parse_str($input, $output);
} else {
parse_str($input, $output);
}
return $output;
} else {
return array();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::params (   $key)

Fetch a PUT|POST|GET parameter value.

The preferred method to fetch the value of a PUT, POST, or GET parameter (searched in that order).

Parameters
string$keyThe paramter name
Returns
string|null The value of parameter, or NULL if parameter not found

Definition at line 199 of file Request.php.

Referenced by isAjax().

{
foreach ( array('put', 'post', 'get') as $dataSource ) {
$source = $this->$dataSource;
if ( isset($source[(string)$key]) ) {
return $source[(string)$key];
}
}
return null;
}

+ Here is the caller graph for this function:

Slim_Http_Request::post (   $key = null)

Fetch POST parameter(s)

Parameters
string$keyName of parameter
Returns
array|string|null All parameters, parameter value if $key and parameter exists, or NULL if $key and parameter does not exist.

Definition at line 227 of file Request.php.

References arrayOrArrayValue().

Referenced by __construct(), and checkForHttpMethodOverride().

{
return $this->arrayOrArrayValue($this->post, $key);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_Http_Request::put (   $key = null)

Fetch PUT parameter(s)

Parameters
string$keyName of parameter
Returns
array|string|null All parameters, parameter value if $key and parameter exists, or NULL if $key and parameter does not exist.

Definition at line 238 of file Request.php.

References arrayOrArrayValue().

Referenced by __construct(), and checkForHttpMethodOverride().

{
return $this->arrayOrArrayValue($this->put, $key);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Slim_Http_Request::stripSlashesIfMagicQuotes (   $rawData)
static

Strip slashes from string or array of strings.

Parameters
array | string$rawData
Returns
array|string

Definition at line 336 of file Request.php.

Referenced by __construct().

{
if ( get_magic_quotes_gpc() ) {
return is_array($rawData) ? array_map(array('self', 'stripSlashesIfMagicQuotes'), $rawData) : stripslashes($rawData);
} else {
return $rawData;
}
}

+ Here is the caller graph for this function:

Field Documentation

Slim_Http_Request::$additionalHeaders = array('content-type', 'content-length', 'php-auth-user', 'php-auth-pw', 'auth-type', 'x-requested-with')
protected

Definition at line 72 of file Request.php.

Slim_Http_Request::$body
protected

Definition at line 98 of file Request.php.

Referenced by getBody().

Slim_Http_Request::$contentType
protected

Definition at line 103 of file Request.php.

Referenced by getContentType().

Slim_Http_Request::$cookies
protected

Definition at line 78 of file Request.php.

Slim_Http_Request::$get
protected

Definition at line 83 of file Request.php.

Slim_Http_Request::$headers
protected

Definition at line 66 of file Request.php.

Referenced by loadHttpHeaders().

Slim_Http_Request::$method
protected

Definition at line 61 of file Request.php.

Referenced by getMethod().

Slim_Http_Request::$post
protected

Definition at line 88 of file Request.php.

Referenced by checkForHttpMethodOverride().

Slim_Http_Request::$put
protected

Definition at line 93 of file Request.php.

Slim_Http_Request::$resource
protected

Definition at line 108 of file Request.php.

Referenced by getResourceUri().

Slim_Http_Request::$root
protected

Definition at line 116 of file Request.php.

Referenced by getRootUri().

const Slim_Http_Request::METHOD_DELETE = 'DELETE'

Definition at line 54 of file Request.php.

Referenced by Slim\delete(), and isDelete().

const Slim_Http_Request::METHOD_GET = 'GET'

Definition at line 51 of file Request.php.

Referenced by Slim\get(), and isGet().

const Slim_Http_Request::METHOD_HEAD = 'HEAD'

Definition at line 50 of file Request.php.

Referenced by Slim\get(), and isHead().

const Slim_Http_Request::METHOD_OPTIONS = 'OPTIONS'

Definition at line 55 of file Request.php.

Referenced by isOptions(), and Slim\options().

const Slim_Http_Request::METHOD_OVERRIDE = '_METHOD'

Definition at line 56 of file Request.php.

Referenced by checkForHttpMethodOverride().

const Slim_Http_Request::METHOD_POST = 'POST'

Definition at line 52 of file Request.php.

Referenced by isPost(), and Slim\post().

const Slim_Http_Request::METHOD_PUT = 'PUT'

Definition at line 53 of file Request.php.

Referenced by isPut(), and Slim\put().


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