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

Public Member Functions

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

Static Public Member Functions

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

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. More...
 
 arrayValueForKey (array &$array, $key)
 Fetch value from array. More...
 
 loadPutParameters ()
 Get PUT parameters. More...
 
 loadHttpHeaders ()
 Get HTTP request headers. More...
 
 convertHttpHeaderName ( $name)
 Convert HTTP header name. More...
 
 checkForHttpMethodOverride ()
 Check for HTTP request method override. More...
 

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

◆ __construct()

Slim_Http_Request::__construct ( )

Constructor.

Definition at line 121 of file Request.php.

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

121  {
122  $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
123  $this->headers = $this->loadHttpHeaders();
124  $this->body = @file_get_contents('php://input');
125  $this->get = self::stripSlashesIfMagicQuotes($_GET);
126  $this->post = self::stripSlashesIfMagicQuotes($_POST);
127  $this->put = self::stripSlashesIfMagicQuotes($this->loadPutParameters());
128  $this->cookies = self::stripSlashesIfMagicQuotes($_COOKIE);
129  $this->root = Slim_Http_Uri::getBaseUri(true);
130  $this->resource = Slim_Http_Uri::getUri(true);
132  }
cookies( $key=null)
Fetch COOKIE value(s)
Definition: Request.php:249
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
checkForHttpMethodOverride()
Check for HTTP request method override.
Definition: Request.php:395
$_GET["client_id"]
post( $key=null)
Fetch POST parameter(s)
Definition: Request.php:227
loadHttpHeaders()
Get HTTP request headers.
Definition: Request.php:366
put( $key=null)
Fetch PUT parameter(s)
Definition: Request.php:238
headers( $key=null)
Get HTTP request header.
Definition: Request.php:260
loadPutParameters()
Get PUT parameters.
Definition: Request.php:348
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
$_POST["username"]
static getBaseUri( $reload=false)
Get Base URI without trailing slash.
Definition: Uri.php:69
static getUri( $reload=false)
Get URI with leading slash.
Definition: Uri.php:85
+ Here is the call graph for this function:

Member Function Documentation

◆ arrayOrArrayValue()

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

319  {
320  return is_null($key) ? $array : $this->arrayValueForKey($array, $key);
321  }
arrayValueForKey(array &$array, $key)
Fetch value from array.
Definition: Request.php:327
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ arrayValueForKey()

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

Fetch value from array.

Returns
mixed|null

Definition at line 327 of file Request.php.

References string.

Referenced by arrayOrArrayValue().

327  {
328  return isset($array[(string)$key]) ? $array[(string)$key] : null;
329  }
Add rich text string
The name of the decorator.
+ Here is the caller graph for this function:

◆ checkForHttpMethodOverride()

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(), post(), and put().

Referenced by __construct().

395  {
396  if ( isset($this->post[self::METHOD_OVERRIDE]) ) {
397  $this->method = $this->post[self::METHOD_OVERRIDE];
398  unset($this->post[self::METHOD_OVERRIDE]);
399  if ( $this->isPut() ) {
400  $this->put = $this->post;
401  }
402  }
403  }
post( $key=null)
Fetch POST parameter(s)
Definition: Request.php:227
put( $key=null)
Fetch PUT parameter(s)
Definition: Request.php:238
isPut()
Is this a PUT request?
Definition: Request.php:154
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convertHttpHeaderName()

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

382  {
383  return str_replace('_', '-', strtolower($name));
384  }
+ Here is the caller graph for this function:

◆ cookies()

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

249  {
250  return $this->arrayOrArrayValue($this->cookies, $key);
251  }
cookies( $key=null)
Fetch COOKIE value(s)
Definition: Request.php:249
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

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

216  {
217  return $this->arrayOrArrayValue($this->get, $key);
218  }
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319
+ Here is the call graph for this function:

◆ getBody()

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.

268  {
269  return $this->body;
270  }

◆ getContentType()

Slim_Http_Request::getContentType ( )

Get HTTP request content type.

Returns
string

Definition at line 284 of file Request.php.

References $contentType, $header, and headers().

Referenced by loadPutParameters().

284  {
285  if ( !isset($this->contentType) ) {
286  $contentType = 'application/x-www-form-urlencoded';
287  $header = $this->headers('CONTENT_TYPE');
288  if ( !is_null($header) ) {
289  $headerParts = preg_split('/\s*;\s*/', $header);
290  $contentType = $headerParts[0];
291  }
292  $this->contentType = $contentType;
293  }
294  return $this->contentType;
295  }
$header
headers( $key=null)
Get HTTP request header.
Definition: Request.php:260
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMethod()

Slim_Http_Request::getMethod ( )

Get HTTP method.

Returns
string

Definition at line 276 of file Request.php.

References $method.

276  {
277  return $this->method;
278  }

◆ getResourceUri()

Slim_Http_Request::getResourceUri ( )

Get HTTP request resource URI.

Returns
string

Definition at line 301 of file Request.php.

References $resource.

301  {
302  return $this->resource;
303  }

◆ getRootUri()

Slim_Http_Request::getRootUri ( )

Get HTTP request root URI.

Returns
string

Definition at line 309 of file Request.php.

References $root.

309  {
310  return $this->root;
311  }

◆ headers()

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

260  {
261  return is_null($key) ? $this->headers : $this->arrayOrArrayValue($this->headers, $this->convertHttpHeaderName($key));
262  }
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319
convertHttpHeaderName( $name)
Convert HTTP header name.
Definition: Request.php:382
headers( $key=null)
Get HTTP request header.
Definition: Request.php:260
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAjax()

Slim_Http_Request::isAjax ( )

Is this a XHR request?

Returns
bool

Definition at line 186 of file Request.php.

References headers(), and params().

186  {
187  return ( $this->params('isajax') || $this->headers('X_REQUESTED_WITH') === 'XMLHttpRequest' );
188  }
params( $key)
Fetch a PUT|POST|GET parameter value.
Definition: Request.php:199
headers( $key=null)
Get HTTP request header.
Definition: Request.php:260
+ Here is the call graph for this function:

◆ isDelete()

Slim_Http_Request::isDelete ( )

Is this a DELETE request?

Returns
bool

Definition at line 162 of file Request.php.

162  {
163  return $this->method === self::METHOD_DELETE;
164  }

◆ isGet()

Slim_Http_Request::isGet ( )

Is this a GET request?

Returns
bool

Definition at line 138 of file Request.php.

138  {
139  return $this->method === self::METHOD_GET;
140  }

◆ isHead()

Slim_Http_Request::isHead ( )

Is this a HEAD request?

Returns
bool

Definition at line 170 of file Request.php.

170  {
171  return $this->method === self::METHOD_HEAD;
172  }

◆ isOptions()

Slim_Http_Request::isOptions ( )

Is this a OPTIONS request?

Returns
bool

Definition at line 178 of file Request.php.

178  {
179  return $this->method === self::METHOD_OPTIONS;
180  }

◆ isPost()

Slim_Http_Request::isPost ( )

Is this a POST request?

Returns
bool

Definition at line 146 of file Request.php.

146  {
147  return $this->method === self::METHOD_POST;
148  }

◆ isPut()

Slim_Http_Request::isPut ( )

Is this a PUT request?

Returns
bool

Definition at line 154 of file Request.php.

Referenced by checkForHttpMethodOverride().

154  {
155  return $this->method === self::METHOD_PUT;
156  }
+ Here is the caller graph for this function:

◆ loadHttpHeaders()

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 $_SERVER, $headers, array, and convertHttpHeaderName().

Referenced by __construct().

366  {
367  $headers = array();
368  foreach ( $_SERVER as $key => $value ) {
369  $key = $this->convertHttpHeaderName($key);
370  if ( strpos($key, 'http-') === 0 || in_array($key, $this->additionalHeaders) ) {
371  $name = str_replace('http-', '', $key);
372  $headers[$name] = $value;
373  }
374  }
375  return $headers;
376  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
convertHttpHeaderName( $name)
Convert HTTP header name.
Definition: Request.php:382
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadPutParameters()

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 $output, array, and getContentType().

Referenced by __construct().

348  {
349  if ( $this->getContentType() === 'application/x-www-form-urlencoded' ) {
350  $input = is_string($this->body) ? $this->body : '';
351  if ( function_exists('mb_parse_str') ) {
352  mb_parse_str($input, $output);
353  } else {
354  parse_str($input, $output);
355  }
356  return $output;
357  } else {
358  return array();
359  }
360  }
getContentType()
Get HTTP request content type.
Definition: Request.php:284
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ params()

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.

References array, and string.

Referenced by isAjax().

199  {
200  foreach ( array('put', 'post', 'get') as $dataSource ) {
201  $source = $this->$dataSource;
202  if ( isset($source[(string)$key]) ) {
203  return $source[(string)$key];
204  }
205  }
206  return null;
207  }
Add rich text string
The name of the decorator.
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ post()

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

227  {
228  return $this->arrayOrArrayValue($this->post, $key);
229  }
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319
post( $key=null)
Fetch POST parameter(s)
Definition: Request.php:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ put()

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

238  {
239  return $this->arrayOrArrayValue($this->put, $key);
240  }
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319
put( $key=null)
Fetch PUT parameter(s)
Definition: Request.php:238
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stripSlashesIfMagicQuotes()

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.

References array.

336  {
337  if ( get_magic_quotes_gpc() ) {
338  return is_array($rawData) ? array_map(array('self', 'stripSlashesIfMagicQuotes'), $rawData) : stripslashes($rawData);
339  } else {
340  return $rawData;
341  }
342  }
Create styles array
The data for the language used.

Field Documentation

◆ $additionalHeaders

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.

◆ $body

Slim_Http_Request::$body
protected

Definition at line 98 of file Request.php.

Referenced by getBody().

◆ $contentType

Slim_Http_Request::$contentType
protected

Definition at line 103 of file Request.php.

Referenced by getContentType().

◆ $cookies

Slim_Http_Request::$cookies
protected

Definition at line 78 of file Request.php.

◆ $get

Slim_Http_Request::$get
protected

Definition at line 83 of file Request.php.

◆ $headers

Slim_Http_Request::$headers
protected

Definition at line 66 of file Request.php.

Referenced by loadHttpHeaders().

◆ $method

Slim_Http_Request::$method
protected

Definition at line 61 of file Request.php.

Referenced by getMethod().

◆ $post

Slim_Http_Request::$post
protected

Definition at line 88 of file Request.php.

Referenced by checkForHttpMethodOverride().

◆ $put

Slim_Http_Request::$put
protected

Definition at line 93 of file Request.php.

◆ $resource

Slim_Http_Request::$resource
protected

Definition at line 108 of file Request.php.

Referenced by getResourceUri().

◆ $root

Slim_Http_Request::$root
protected

Definition at line 116 of file Request.php.

Referenced by getRootUri().

◆ METHOD_DELETE

const Slim_Http_Request::METHOD_DELETE = 'DELETE'

Definition at line 54 of file Request.php.

Referenced by Slim\delete().

◆ METHOD_GET

const Slim_Http_Request::METHOD_GET = 'GET'

Definition at line 51 of file Request.php.

Referenced by Slim\get().

◆ METHOD_HEAD

const Slim_Http_Request::METHOD_HEAD = 'HEAD'

Definition at line 50 of file Request.php.

Referenced by Slim\get().

◆ METHOD_OPTIONS

const Slim_Http_Request::METHOD_OPTIONS = 'OPTIONS'

Definition at line 55 of file Request.php.

Referenced by Slim\options().

◆ METHOD_OVERRIDE

const Slim_Http_Request::METHOD_OVERRIDE = '_METHOD'

Definition at line 56 of file Request.php.

◆ METHOD_POST

const Slim_Http_Request::METHOD_POST = 'POST'

Definition at line 52 of file Request.php.

Referenced by Slim\post().

◆ METHOD_PUT

const Slim_Http_Request::METHOD_PUT = 'PUT'

Definition at line 53 of file Request.php.

Referenced by Slim\put().


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