ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

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');
129 $this->root = Slim_Http_Uri::getBaseUri(true);
130 $this->resource = Slim_Http_Uri::getUri(true);
132 }
$_GET["client_id"]
cookies( $key=null)
Fetch COOKIE value(s)
Definition: Request.php:249
headers( $key=null)
Get HTTP request header.
Definition: Request.php:260
put( $key=null)
Fetch PUT parameter(s)
Definition: Request.php:238
checkForHttpMethodOverride()
Check for HTTP request method override.
Definition: Request.php:395
static stripSlashesIfMagicQuotes( $rawData)
Strip slashes from string or array of strings.
Definition: Request.php:336
loadPutParameters()
Get PUT parameters.
Definition: Request.php:348
post( $key=null)
Fetch POST parameter(s)
Definition: Request.php:227
loadHttpHeaders()
Get HTTP request headers.
Definition: Request.php:366
static getUri( $reload=false)
Get URI with leading slash.
Definition: Uri.php:85
static getBaseUri( $reload=false)
Get Base URI without trailing slash.
Definition: Uri.php:69
$_POST['username']
Definition: cron.php:12
$_COOKIE["ilClientId"]
Definition: cron.php:11
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

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

+ 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.

319 {
320 return is_null($key) ? $array : $this->arrayValueForKey($array, $key);
321 }
arrayValueForKey(array &$array, $key)
Fetch value from array.
Definition: Request.php:327

References arrayValueForKey().

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

+ 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.

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

Referenced by arrayOrArrayValue().

+ 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.

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 }
const METHOD_OVERRIDE
Definition: Request.php:56
isPut()
Is this a PUT request?
Definition: Request.php:154

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

Referenced by __construct().

+ 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.

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

Referenced by headers(), and loadHttpHeaders().

+ 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.

249 {
250 return $this->arrayOrArrayValue($this->cookies, $key);
251 }
arrayOrArrayValue(array &$array, $key=null)
Fetch array or array value.
Definition: Request.php:319

References arrayOrArrayValue(), and cookies().

Referenced by __construct(), and cookies().

+ 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.

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

References arrayOrArrayValue().

+ 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.

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

References $body.

◆ getContentType()

Slim_Http_Request::getContentType ( )

Get HTTP request content type.

Returns
string

Definition at line 284 of file Request.php.

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

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

Referenced by loadPutParameters().

+ 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.

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

References $method.

◆ getResourceUri()

Slim_Http_Request::getResourceUri ( )

Get HTTP request resource URI.

Returns
string

Definition at line 301 of file Request.php.

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

References $resource.

◆ getRootUri()

Slim_Http_Request::getRootUri ( )

Get HTTP request root URI.

Returns
string

Definition at line 309 of file Request.php.

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

References $root.

◆ 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.

260 {
261 return is_null($key) ? $this->headers : $this->arrayOrArrayValue($this->headers, $this->convertHttpHeaderName($key));
262 }
convertHttpHeaderName( $name)
Convert HTTP header name.
Definition: Request.php:382

References arrayOrArrayValue(), convertHttpHeaderName(), and headers().

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

+ 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.

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

References headers(), and params().

+ 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 }
const METHOD_DELETE
Definition: Request.php:54

References METHOD_DELETE.

◆ 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 }
const METHOD_GET
Definition: Request.php:51

References METHOD_GET.

◆ 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 }
const METHOD_HEAD
Definition: Request.php:50

References METHOD_HEAD.

◆ 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 }
const METHOD_OPTIONS
Definition: Request.php:55

References METHOD_OPTIONS.

◆ 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 }
const METHOD_POST
Definition: Request.php:52

References METHOD_POST.

◆ isPut()

Slim_Http_Request::isPut ( )

Is this a PUT request?

Returns
bool

Definition at line 154 of file Request.php.

154 {
155 return $this->method === self::METHOD_PUT;
156 }
const METHOD_PUT
Definition: Request.php:53

References METHOD_PUT.

Referenced by checkForHttpMethodOverride().

+ 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.

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 }

References $_SERVER, $headers, and convertHttpHeaderName().

Referenced by __construct().

+ 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.

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

References getContentType().

Referenced by __construct().

+ 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.

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 }

Referenced by isAjax().

+ 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.

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

References arrayOrArrayValue(), and post().

Referenced by __construct(), checkForHttpMethodOverride(), and post().

+ 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.

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

References arrayOrArrayValue(), and put().

Referenced by __construct(), checkForHttpMethodOverride(), and put().

+ 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.

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 }

Referenced by __construct().

+ Here is the caller graph for this function:

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

◆ METHOD_GET

const Slim_Http_Request::METHOD_GET = 'GET'

Definition at line 51 of file Request.php.

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

◆ METHOD_HEAD

const Slim_Http_Request::METHOD_HEAD = 'HEAD'

Definition at line 50 of file Request.php.

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

◆ METHOD_OPTIONS

const Slim_Http_Request::METHOD_OPTIONS = 'OPTIONS'

Definition at line 55 of file Request.php.

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

◆ METHOD_OVERRIDE

const Slim_Http_Request::METHOD_OVERRIDE = '_METHOD'

Definition at line 56 of file Request.php.

Referenced by checkForHttpMethodOverride().

◆ METHOD_POST

const Slim_Http_Request::METHOD_POST = 'POST'

Definition at line 52 of file Request.php.

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

◆ METHOD_PUT

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: