ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Slim\Http\Request Class Reference

Request. More...

+ Inheritance diagram for Slim\Http\Request:
+ Collaboration diagram for Slim\Http\Request:

Public Member Functions

 __construct ( $method, UriInterface $uri, HeadersInterface $headers, array $cookies, array $serverParams, StreamInterface $body, array $uploadedFiles=[])
 Create new HTTP request. More...
 
 __clone ()
 This method is applied to the cloned object after PHP performs an initial shallow-copy. More...
 
 getMethod ()
 Retrieves the HTTP method of the request. More...
 
 getOriginalMethod ()
 Get the original HTTP method (ignore override). More...
 
 withMethod ($method)
 Return an instance with the provided HTTP method. More...
 
 isMethod ($method)
 Does this request use a given method? More...
 
 isGet ()
 Is this a GET request? More...
 
 isPost ()
 Is this a POST request? More...
 
 isPut ()
 Is this a PUT request? More...
 
 isPatch ()
 Is this a PATCH request? More...
 
 isDelete ()
 Is this a DELETE request? More...
 
 isHead ()
 Is this a HEAD request? More...
 
 isOptions ()
 Is this a OPTIONS request? More...
 
 isXhr ()
 Is this an XHR request? More...
 
 getRequestTarget ()
 Retrieves the message's request target. More...
 
 withRequestTarget ($requestTarget)
 Return an instance with the specific request-target. More...
 
 getUri ()
 Retrieves the URI instance. More...
 
 withUri (UriInterface $uri, $preserveHost=false)
 Returns an instance with the provided URI. More...
 
 getContentType ()
 Get request content type. More...
 
 getMediaType ()
 Get request media type, if known. More...
 
 getMediaTypeParams ()
 Get request media type params, if known. More...
 
 getContentCharset ()
 Get request content character set, if known. More...
 
 getContentLength ()
 Get request content length, if known. More...
 
 getCookieParams ()
 Retrieve cookies. More...
 
 getCookieParam ($key, $default=null)
 Fetch cookie value from cookies sent by the client to the server. More...
 
 withCookieParams (array $cookies)
 Return an instance with the specified cookies. More...
 
 getQueryParams ()
 Retrieve query string arguments. More...
 
 withQueryParams (array $query)
 Return an instance with the specified query string arguments. More...
 
 getUploadedFiles ()
 Retrieve normalized file upload data. More...
 
 withUploadedFiles (array $uploadedFiles)
 Create a new instance with the specified uploaded files. More...
 
 getServerParams ()
 Retrieve server parameters. More...
 
 getServerParam ($key, $default=null)
 Retrieve a server parameter. More...
 
 getAttributes ()
 Retrieve attributes derived from the request. More...
 
 getAttribute ($name, $default=null)
 Retrieve a single derived request attribute. More...
 
 withAttribute ($name, $value)
 Return an instance with the specified derived request attribute. More...
 
 withAttributes (array $attributes)
 Create a new instance with the specified derived request attributes. More...
 
 withoutAttribute ($name)
 Return an instance that removes the specified derived request attribute. More...
 
 getParsedBody ()
 Retrieve any parameters provided in the request body. More...
 
 withParsedBody ($data)
 Return an instance with the specified body parameters. More...
 
 reparseBody ()
 Force Body to be parsed again. More...
 
 registerMediaTypeParser ($mediaType, callable $callable)
 Register media type parser. More...
 
 getParam ($key, $default=null)
 Fetch request parameter value from body or query string (in that order). More...
 
 getParsedBodyParam ($key, $default=null)
 Fetch parameter value from request body. More...
 
 getQueryParam ($key, $default=null)
 Fetch parameter value from query string. More...
 
 getParams (array $only=null)
 Fetch associative array of body and query string parameters. More...
 
- Public Member Functions inherited from Slim\Http\Message
 __set ($name, $value)
 Disable magic setter to ensure immutability. More...
 
 getProtocolVersion ()
 Retrieves the HTTP protocol version as a string. More...
 
 withProtocolVersion ($version)
 Return an instance with the specified HTTP protocol version. More...
 
 getHeaders ()
 Retrieves all message header values. More...
 
 hasHeader ($name)
 Checks if a header exists by the given case-insensitive name. More...
 
 getHeader ($name)
 Retrieves a message header value by the given case-insensitive name. More...
 
 getHeaderLine ($name)
 Retrieves a comma-separated string of the values for a single header. More...
 
 withHeader ($name, $value)
 Return an instance with the provided value replacing the specified header. More...
 
 withAddedHeader ($name, $value)
 Return an instance with the specified header appended with the given value. More...
 
 withoutHeader ($name)
 Return an instance without the specified header. More...
 
 getBody ()
 Gets the body of the message. More...
 
 withBody (StreamInterface $body)
 Return an instance with the specified message body. More...
 

Static Public Member Functions

static createFromEnvironment (Environment $environment)
 Create new HTTP request with data extracted from the application Environment object. More...
 

Protected Member Functions

 filterMethod ($method)
 Validate the HTTP method. More...
 

Protected Attributes

 $method
 
 $originalMethod
 
 $uri
 
 $requestTarget
 
 $queryParams
 
 $cookies
 
 $serverParams
 
 $attributes
 
 $bodyParsed = false
 
 $bodyParsers = []
 
 $uploadedFiles
 
 $validMethods
 
- Protected Attributes inherited from Slim\Http\Message
 $protocolVersion = '1.1'
 
 $headers
 
 $body
 

Additional Inherited Members

- Static Protected Attributes inherited from Slim\Http\Message
static $validProtocolVersions
 

Detailed Description

Request.

This class represents an HTTP request. It manages the request method, URI, headers, cookies, and body according to the PSR-7 standard.

https://github.com/php-fig/http-message/blob/master/src/RequestInterface.php https://github.com/php-fig/http-message/blob/master/src/ServerRequestInterface.php

Definition at line 33 of file Request.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\Http\Request::__construct (   $method,
UriInterface  $uri,
HeadersInterface  $headers,
array  $cookies,
array  $serverParams,
StreamInterface  $body,
array  $uploadedFiles = [] 
)

Create new HTTP request.

Adds a host header when none was provided and a host is defined in uri.

Parameters
string$methodThe request method
UriInterface$uriThe request URI object
HeadersInterface$headersThe request headers collection
array$cookiesThe request cookies collection
array$serverParamsThe server environment variables
StreamInterface$bodyThe request body object
array$uploadedFilesThe request uploadedFiles collection
Exceptions
InvalidMethodExceptionon invalid HTTP method

Definition at line 173 of file Request.php.

References Slim\Http\Message\$body, Slim\Http\Request\$cookies, $data, Slim\Http\Message\$headers, Slim\Http\Request\$method, $result, Slim\Http\Request\$serverParams, Slim\Http\Request\$uploadedFiles, Slim\Http\Request\$uri, Slim\Http\Request\filterMethod(), and Slim\Http\Request\registerMediaTypeParser().

181  {
182  try {
183  $this->originalMethod = $this->filterMethod($method);
184  } catch (InvalidMethodException $e) {
185  $this->originalMethod = $method;
186  }
187 
188  $this->uri = $uri;
189  $this->headers = $headers;
190  $this->cookies = $cookies;
191  $this->serverParams = $serverParams;
192  $this->attributes = new Collection();
193  $this->body = $body;
194  $this->uploadedFiles = $uploadedFiles;
195 
196  if (isset($serverParams['SERVER_PROTOCOL'])) {
197  $this->protocolVersion = str_replace('HTTP/', '', $serverParams['SERVER_PROTOCOL']);
198  }
199 
200  if (!$this->headers->has('Host') && $this->uri->getHost() !== '') {
201  $port = $this->uri->getPort() ? ":{$this->uri->getPort()}" : '';
202 
203  $this->headers->set('Host', $this->uri->getHost() . $port);
204  }
205 
206  $this->registerMediaTypeParser('application/json', function ($input) {
207  $result = json_decode($input, true);
208  if (!is_array($result)) {
209  return null;
210  }
211  return $result;
212  });
213 
214  $this->registerMediaTypeParser('application/xml', function ($input) {
215  $backup = libxml_disable_entity_loader(true);
216  $backup_errors = libxml_use_internal_errors(true);
217  $result = simplexml_load_string($input);
218  libxml_disable_entity_loader($backup);
219  libxml_clear_errors();
220  libxml_use_internal_errors($backup_errors);
221  if ($result === false) {
222  return null;
223  }
224  return $result;
225  });
226 
227  $this->registerMediaTypeParser('text/xml', function ($input) {
228  $backup = libxml_disable_entity_loader(true);
229  $backup_errors = libxml_use_internal_errors(true);
230  $result = simplexml_load_string($input);
231  libxml_disable_entity_loader($backup);
232  libxml_clear_errors();
233  libxml_use_internal_errors($backup_errors);
234  if ($result === false) {
235  return null;
236  }
237  return $result;
238  });
239 
240  $this->registerMediaTypeParser('application/x-www-form-urlencoded', function ($input) {
241  parse_str($input, $data);
242  return $data;
243  });
244 
245  // if the request had an invalid method, we can throw it now
246  if (isset($e) && $e instanceof InvalidMethodException) {
247  throw $e;
248  }
249  }
$result
registerMediaTypeParser($mediaType, callable $callable)
Register media type parser.
Definition: Request.php:1119
filterMethod($method)
Validate the HTTP method.
Definition: Request.php:340
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

Slim\Http\Request::__clone ( )

This method is applied to the cloned object after PHP performs an initial shallow-copy.

This method completes a deep-copy by creating new objects for the cloned object's internal reference pointers.

Definition at line 257 of file Request.php.

References Slim\Http\Request\$attributes, Slim\Http\Message\$body, and Slim\Http\Message\$headers.

258  {
259  $this->headers = clone $this->headers;
260  $this->attributes = clone $this->attributes;
261  $this->body = clone $this->body;
262  }

◆ createFromEnvironment()

static Slim\Http\Request::createFromEnvironment ( Environment  $environment)
static

Create new HTTP request with data extracted from the application Environment object.

Parameters
Environment$environmentThe Slim application Environment
Returns
static

Definition at line 138 of file Request.php.

References $_POST, Slim\Http\Message\$body, Slim\Http\Request\$cookies, Slim\Http\Message\$headers, Slim\Http\Request\$method, Slim\Http\Request\$serverParams, Slim\Http\Request\$uploadedFiles, Slim\Http\Request\$uri, Slim\Collection\all(), Slim\Http\Headers\createFromEnvironment(), Slim\Http\UploadedFile\createFromEnvironment(), Slim\Http\Uri\createFromEnvironment(), and Slim\Http\Cookies\parseHeader().

139  {
140  $method = $environment['REQUEST_METHOD'];
141  $uri = Uri::createFromEnvironment($environment);
143  $cookies = Cookies::parseHeader($headers->get('Cookie', []));
144  $serverParams = $environment->all();
145  $body = new RequestBody();
147 
148  $request = new static($method, $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
149 
150  if ($method === 'POST' &&
151  in_array($request->getMediaType(), ['application/x-www-form-urlencoded', 'multipart/form-data'])
152  ) {
153  // parsed body must be $_POST
154  $request = $request->withParsedBody($_POST);
155  }
156  return $request;
157  }
static static createFromEnvironment(Environment $environment)
Create new headers collection with data extracted from the application Environment object...
Definition: Headers.php:51
static createFromEnvironment(Environment $env)
Create new Uri from environment.
Definition: Uri.php:166
static parseHeader($header)
Parse HTTP request Cookie: header and extract into a PHP associative array.
Definition: Cookies.php:172
static createFromEnvironment(Environment $env)
Create a normalized tree of UploadedFile instances from the Environment.
$_POST["username"]
+ Here is the call graph for this function:

◆ filterMethod()

Slim\Http\Request::filterMethod (   $method)
protected

Validate the HTTP method.

Parameters
null | string$method
Returns
null|string
Exceptions

Definition at line 340 of file Request.php.

References Slim\Http\Request\$method.

Referenced by Slim\Http\Request\__construct(), Slim\Http\Request\getMethod(), and Slim\Http\Request\withMethod().

341  {
342  if ($method === null) {
343  return $method;
344  }
345 
346  if (!is_string($method)) {
347  throw new InvalidArgumentException(sprintf(
348  'Unsupported HTTP method; must be a string, received %s',
349  (is_object($method) ? get_class($method) : gettype($method))
350  ));
351  }
352 
353  $method = strtoupper($method);
354  if (preg_match("/^[!#$%&'*+.^_`|~0-9a-z-]+$/i", $method) !== 1) {
355  throw new InvalidMethodException($this, $method);
356  }
357 
358  return $method;
359  }
+ Here is the caller graph for this function:

◆ getAttribute()

Slim\Http\Request::getAttribute (   $name,
  $default = null 
)

Retrieve a single derived request attribute.

Retrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided.

This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.

See also
getAttributes()
Parameters
string$nameThe attribute name.
mixed$defaultDefault value to return if the attribute does not exist.
Returns
mixed

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 928 of file Request.php.

References $name.

929  {
930  return $this->attributes->get($name, $default);
931  }
if($format !==null) $name
Definition: metadata.php:146

◆ getAttributes()

Slim\Http\Request::getAttributes ( )

Retrieve attributes derived from the request.

The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.

Returns
array Attributes derived from the request.

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 908 of file Request.php.

909  {
910  return $this->attributes->all();
911  }

◆ getContentCharset()

Slim\Http\Request::getContentCharset ( )

Get request content character set, if known.

Note: This method is not part of the PSR-7 standard.

Returns
string|null

Definition at line 669 of file Request.php.

References Slim\Http\Request\getMediaTypeParams().

670  {
671  $mediaTypeParams = $this->getMediaTypeParams();
672  if (isset($mediaTypeParams['charset'])) {
673  return $mediaTypeParams['charset'];
674  }
675 
676  return null;
677  }
getMediaTypeParams()
Get request media type params, if known.
Definition: Request.php:646
+ Here is the call graph for this function:

◆ getContentLength()

Slim\Http\Request::getContentLength ( )

Get request content length, if known.

Note: This method is not part of the PSR-7 standard.

Returns
int|null

Definition at line 686 of file Request.php.

References $result.

687  {
688  $result = $this->headers->get('Content-Length');
689 
690  return $result ? (int)$result[0] : null;
691  }
$result

◆ getContentType()

Slim\Http\Request::getContentType ( )

Get request content type.

Note: This method is not part of the PSR-7 standard.

Returns
string|null The request content type, if known

Definition at line 613 of file Request.php.

References $result, and Slim\Http\Message\getHeader().

Referenced by Slim\Http\Request\getMediaType(), and Slim\Http\Request\getMediaTypeParams().

614  {
615  $result = $this->getHeader('Content-Type');
616 
617  return $result ? $result[0] : null;
618  }
$result
getHeader($name)
Retrieves a message header value by the given case-insensitive name.
Definition: Message.php:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCookieParam()

Slim\Http\Request::getCookieParam (   $key,
  $default = null 
)

Fetch cookie value from cookies sent by the client to the server.

Note: This method is not part of the PSR-7 standard.

Parameters
string$keyThe attribute name.
mixed$defaultDefault value to return if the attribute does not exist.
Returns
mixed

Definition at line 722 of file Request.php.

References Slim\Http\Request\$cookies, $key, $result, and Slim\Http\Request\getCookieParams().

723  {
724  $cookies = $this->getCookieParams();
725  $result = $default;
726  if (isset($cookies[$key])) {
727  $result = $cookies[$key];
728  }
729 
730  return $result;
731  }
$result
getCookieParams()
Retrieve cookies.
Definition: Request.php:707
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getCookieParams()

Slim\Http\Request::getCookieParams ( )

Retrieve cookies.

Retrieves cookies sent by the client to the server.

The data MUST be compatible with the structure of the $_COOKIE superglobal.

Returns
array

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 707 of file Request.php.

References Slim\Http\Request\$cookies.

Referenced by Slim\Http\Request\getCookieParam().

708  {
709  return $this->cookies;
710  }
+ Here is the caller graph for this function:

◆ getMediaType()

Slim\Http\Request::getMediaType ( )

Get request media type, if known.

Note: This method is not part of the PSR-7 standard.

Returns
string|null The request media type, minus content-type params

Definition at line 627 of file Request.php.

References $contentType, and Slim\Http\Request\getContentType().

Referenced by Slim\Http\Request\getParsedBody().

628  {
629  $contentType = $this->getContentType();
630  if ($contentType) {
631  $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
632 
633  return strtolower($contentTypeParts[0]);
634  }
635 
636  return null;
637  }
getContentType()
Get request content type.
Definition: Request.php:613
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', $path)) $contentType
Definition: module.php:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMediaTypeParams()

Slim\Http\Request::getMediaTypeParams ( )

Get request media type params, if known.

Note: This method is not part of the PSR-7 standard.

Returns
array

Definition at line 646 of file Request.php.

References $contentType, $i, and Slim\Http\Request\getContentType().

Referenced by Slim\Http\Request\getContentCharset().

647  {
648  $contentType = $this->getContentType();
649  $contentTypeParams = [];
650  if ($contentType) {
651  $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
652  $contentTypePartsLength = count($contentTypeParts);
653  for ($i = 1; $i < $contentTypePartsLength; $i++) {
654  $paramParts = explode('=', $contentTypeParts[$i]);
655  $contentTypeParams[strtolower($paramParts[0])] = $paramParts[1];
656  }
657  }
658 
659  return $contentTypeParams;
660  }
getContentType()
Get request content type.
Definition: Request.php:613
$i
Definition: disco.tpl.php:19
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', $path)) $contentType
Definition: module.php:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMethod()

Slim\Http\Request::getMethod ( )

Retrieves the HTTP method of the request.

Returns
string Returns the request method.

Implements Psr\Http\Message\RequestInterface.

Definition at line 273 of file Request.php.

References Slim\Http\Request\$method, Slim\Http\Request\$originalMethod, Slim\Http\Request\filterMethod(), Slim\Http\Message\getBody(), Slim\Http\Message\getHeaderLine(), and Slim\Http\Request\getParsedBodyParam().

Referenced by Slim\Http\Request\isMethod().

274  {
275  if ($this->method === null) {
276  $this->method = $this->originalMethod;
277  $customMethod = $this->getHeaderLine('X-Http-Method-Override');
278 
279  if ($customMethod) {
280  $this->method = $this->filterMethod($customMethod);
281  } elseif ($this->originalMethod === 'POST') {
282  $overrideMethod = $this->filterMethod($this->getParsedBodyParam('_METHOD'));
283  if ($overrideMethod !== null) {
284  $this->method = $overrideMethod;
285  }
286 
287  if ($this->getBody()->eof()) {
288  $this->getBody()->rewind();
289  }
290  }
291  }
292 
293  return $this->method;
294  }
getBody()
Gets the body of the message.
Definition: Message.php:279
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.
Definition: Message.php:198
getParsedBodyParam($key, $default=null)
Fetch parameter value from request body.
Definition: Request.php:1167
filterMethod($method)
Validate the HTTP method.
Definition: Request.php:340
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOriginalMethod()

Slim\Http\Request::getOriginalMethod ( )

Get the original HTTP method (ignore override).

Note: This method is not part of the PSR-7 standard.

Returns
string

Definition at line 303 of file Request.php.

References Slim\Http\Request\$originalMethod.

304  {
305  return $this->originalMethod;
306  }

◆ getParam()

Slim\Http\Request::getParam (   $key,
  $default = null 
)

Fetch request parameter value from body or query string (in that order).

Note: This method is not part of the PSR-7 standard.

Parameters
string$keyThe parameter key.
mixed$defaultThe default value.
Returns
mixed The parameter value.

Definition at line 1141 of file Request.php.

References $key, $result, Slim\Http\Request\getParsedBody(), and Slim\Http\Request\getQueryParams().

1142  {
1143  $postParams = $this->getParsedBody();
1144  $getParams = $this->getQueryParams();
1145  $result = $default;
1146  if (is_array($postParams) && isset($postParams[$key])) {
1147  $result = $postParams[$key];
1148  } elseif (is_object($postParams) && property_exists($postParams, $key)) {
1149  $result = $postParams->$key;
1150  } elseif (isset($getParams[$key])) {
1151  $result = $getParams[$key];
1152  }
1153 
1154  return $result;
1155  }
$result
getParsedBody()
Retrieve any parameters provided in the request body.
Definition: Request.php:1021
getQueryParams()
Retrieve query string arguments.
Definition: Request.php:774
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getParams()

Slim\Http\Request::getParams ( array  $only = null)

Fetch associative array of body and query string parameters.

Note: This method is not part of the PSR-7 standard.

Parameters
array | null$onlylist the keys to retrieve.
Returns
array|null

Definition at line 1209 of file Request.php.

References $key, $params, array, Slim\Http\Request\getParsedBody(), and Slim\Http\Request\getQueryParams().

1210  {
1211  $params = $this->getQueryParams();
1212  $postParams = $this->getParsedBody();
1213  if ($postParams) {
1214  $params = array_replace($params, (array)$postParams);
1215  }
1216 
1217  if ($only) {
1218  $onlyParams = [];
1219  foreach ($only as $key) {
1220  if (array_key_exists($key, $params)) {
1221  $onlyParams[$key] = $params[$key];
1222  }
1223  }
1224  return $onlyParams;
1225  }
1226 
1227  return $params;
1228  }
$params
Definition: disable.php:11
getParsedBody()
Retrieve any parameters provided in the request body.
Definition: Request.php:1021
getQueryParams()
Retrieve query string arguments.
Definition: Request.php:774
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getParsedBody()

Slim\Http\Request::getParsedBody ( )

Retrieve any parameters provided in the request body.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, this method MUST return the contents of $_POST.

Otherwise, this method may return any results of deserializing the request body content; as parsing returns structured content, the potential types MUST be arrays or objects only. A null value indicates the absence of body content.

Returns
null|array|object The deserialized body parameters, if any. These will typically be an array or object.
Exceptions
RuntimeExceptionif the request body media type parser returns an invalid value

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 1021 of file Request.php.

References Slim\Http\Message\$body, Slim\Http\Request\$bodyParsed, Slim\Http\Message\getBody(), Slim\Http\Request\getMediaType(), and string.

Referenced by Slim\Http\Request\getParam(), Slim\Http\Request\getParams(), and Slim\Http\Request\getParsedBodyParam().

1022  {
1023  if ($this->bodyParsed !== false) {
1024  return $this->bodyParsed;
1025  }
1026 
1027  if (!$this->body) {
1028  return null;
1029  }
1030 
1031  $mediaType = $this->getMediaType();
1032 
1033  // look for a media type with a structured syntax suffix (RFC 6839)
1034  $parts = explode('+', $mediaType);
1035  if (count($parts) >= 2) {
1036  $mediaType = 'application/' . $parts[count($parts)-1];
1037  }
1038 
1039  if (isset($this->bodyParsers[$mediaType]) === true) {
1040  $body = (string)$this->getBody();
1041  $parsed = $this->bodyParsers[$mediaType]($body);
1042 
1043  if (!is_null($parsed) && !is_object($parsed) && !is_array($parsed)) {
1044  throw new RuntimeException(
1045  'Request body media type parser return value must be an array, an object, or null'
1046  );
1047  }
1048  $this->bodyParsed = $parsed;
1049  return $this->bodyParsed;
1050  }
1051 
1052  return null;
1053  }
Add rich text string
getBody()
Gets the body of the message.
Definition: Message.php:279
getMediaType()
Get request media type, if known.
Definition: Request.php:627
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParsedBodyParam()

Slim\Http\Request::getParsedBodyParam (   $key,
  $default = null 
)

Fetch parameter value from request body.

Note: This method is not part of the PSR-7 standard.

Parameters
string$key
mixed$default
Returns
mixed

Definition at line 1167 of file Request.php.

References $key, $result, and Slim\Http\Request\getParsedBody().

Referenced by Slim\Http\Request\getMethod().

1168  {
1169  $postParams = $this->getParsedBody();
1170  $result = $default;
1171  if (is_array($postParams) && isset($postParams[$key])) {
1172  $result = $postParams[$key];
1173  } elseif (is_object($postParams) && property_exists($postParams, $key)) {
1174  $result = $postParams->$key;
1175  }
1176 
1177  return $result;
1178  }
$result
getParsedBody()
Retrieve any parameters provided in the request body.
Definition: Request.php:1021
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQueryParam()

Slim\Http\Request::getQueryParam (   $key,
  $default = null 
)

Fetch parameter value from query string.

Note: This method is not part of the PSR-7 standard.

Parameters
string$key
mixed$default
Returns
mixed

Definition at line 1190 of file Request.php.

References $key, $result, and Slim\Http\Request\getQueryParams().

1191  {
1192  $getParams = $this->getQueryParams();
1193  $result = $default;
1194  if (isset($getParams[$key])) {
1195  $result = $getParams[$key];
1196  }
1197 
1198  return $result;
1199  }
$result
getQueryParams()
Retrieve query string arguments.
Definition: Request.php:774
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getQueryParams()

Slim\Http\Request::getQueryParams ( )

Retrieve query string arguments.

Retrieves the deserialized query string arguments, if any.

Note: the query params might not be in sync with the URI or server params. If you need to ensure you are only getting the original values, you may need to parse the query string from getUri()->getQuery() or from the QUERY_STRING server param.

Returns
array

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 774 of file Request.php.

References Slim\Http\Request\$queryParams.

Referenced by Slim\Http\Request\getParam(), Slim\Http\Request\getParams(), and Slim\Http\Request\getQueryParam().

775  {
776  if (is_array($this->queryParams)) {
777  return $this->queryParams;
778  }
779 
780  if ($this->uri === null) {
781  return [];
782  }
783 
784  parse_str($this->uri->getQuery(), $this->queryParams); // <-- URL decodes data
785 
786  return $this->queryParams;
787  }
+ Here is the caller graph for this function:

◆ getRequestTarget()

Slim\Http\Request::getRequestTarget ( )

Retrieves the message's request target.

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method MUST return the string "/".

Returns
string

Implements Psr\Http\Message\RequestInterface.

Definition at line 490 of file Request.php.

References $path, $query, and Slim\Http\Request\$requestTarget.

491  {
492  if ($this->requestTarget) {
493  return $this->requestTarget;
494  }
495 
496  if ($this->uri === null) {
497  return '/';
498  }
499 
500  $basePath = $this->uri->getBasePath();
501  $path = $this->uri->getPath();
502  $path = $basePath . '/' . ltrim($path, '/');
503 
504  $query = $this->uri->getQuery();
505  if ($query) {
506  $path .= '?' . $query;
507  }
508  $this->requestTarget = $path;
509 
510  return $this->requestTarget;
511  }
$query

◆ getServerParam()

Slim\Http\Request::getServerParam (   $key,
  $default = null 
)

Retrieve a server parameter.

Note: This method is not part of the PSR-7 standard.

Parameters
string$key
mixed$default
Returns
mixed

Definition at line 886 of file Request.php.

References $key, Slim\Http\Request\$serverParams, and Slim\Http\Request\getServerParams().

887  {
888  $serverParams = $this->getServerParams();
889 
890  return isset($serverParams[$key]) ? $serverParams[$key] : $default;
891  }
getServerParams()
Retrieve server parameters.
Definition: Request.php:872
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getServerParams()

Slim\Http\Request::getServerParams ( )

Retrieve server parameters.

Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.

Returns
array

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 872 of file Request.php.

References Slim\Http\Request\$serverParams.

Referenced by Slim\Http\Request\getServerParam().

873  {
874  return $this->serverParams;
875  }
+ Here is the caller graph for this function:

◆ getUploadedFiles()

Slim\Http\Request::getUploadedFiles ( )

Retrieve normalized file upload data.

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr.

These values MAY be prepared from $_FILES or the message body during instantiation, or MAY be injected via withUploadedFiles().

Returns
array An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 835 of file Request.php.

References Slim\Http\Request\$uploadedFiles.

836  {
837  return $this->uploadedFiles;
838  }

◆ getUri()

Slim\Http\Request::getUri ( )

Retrieves the URI instance.

This method MUST return a UriInterface instance.

UriInterface Returns a UriInterface instance representing the URI of the request.

Implements Psr\Http\Message\RequestInterface.

Definition at line 553 of file Request.php.

References Slim\Http\Request\$uri.

554  {
555  return $this->uri;
556  }

◆ isDelete()

Slim\Http\Request::isDelete ( )

Is this a DELETE request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 429 of file Request.php.

References Slim\Http\Request\isMethod().

430  {
431  return $this->isMethod('DELETE');
432  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isGet()

Slim\Http\Request::isGet ( )

Is this a GET request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 381 of file Request.php.

References Slim\Http\Request\isMethod().

382  {
383  return $this->isMethod('GET');
384  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isHead()

Slim\Http\Request::isHead ( )

Is this a HEAD request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 441 of file Request.php.

References Slim\Http\Request\isMethod().

442  {
443  return $this->isMethod('HEAD');
444  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isMethod()

Slim\Http\Request::isMethod (   $method)

Does this request use a given method?

Note: This method is not part of the PSR-7 standard.

Parameters
string$methodHTTP method
Returns
bool

Definition at line 369 of file Request.php.

References Slim\Http\Request\$method, and Slim\Http\Request\getMethod().

Referenced by Slim\Http\Request\isDelete(), Slim\Http\Request\isGet(), Slim\Http\Request\isHead(), Slim\Http\Request\isOptions(), Slim\Http\Request\isPatch(), Slim\Http\Request\isPost(), and Slim\Http\Request\isPut().

370  {
371  return $this->getMethod() === $method;
372  }
getMethod()
Retrieves the HTTP method of the request.
Definition: Request.php:273
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOptions()

Slim\Http\Request::isOptions ( )

Is this a OPTIONS request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 453 of file Request.php.

References Slim\Http\Request\isMethod().

454  {
455  return $this->isMethod('OPTIONS');
456  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isPatch()

Slim\Http\Request::isPatch ( )

Is this a PATCH request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 417 of file Request.php.

References Slim\Http\Request\isMethod().

418  {
419  return $this->isMethod('PATCH');
420  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isPost()

Slim\Http\Request::isPost ( )

Is this a POST request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 393 of file Request.php.

References Slim\Http\Request\isMethod().

394  {
395  return $this->isMethod('POST');
396  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isPut()

Slim\Http\Request::isPut ( )

Is this a PUT request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 405 of file Request.php.

References Slim\Http\Request\isMethod().

406  {
407  return $this->isMethod('PUT');
408  }
isMethod($method)
Does this request use a given method?
Definition: Request.php:369
+ Here is the call graph for this function:

◆ isXhr()

Slim\Http\Request::isXhr ( )

Is this an XHR request?

Note: This method is not part of the PSR-7 standard.

Returns
bool

Definition at line 465 of file Request.php.

References Slim\Http\Message\getHeaderLine().

466  {
467  return $this->getHeaderLine('X-Requested-With') === 'XMLHttpRequest';
468  }
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.
Definition: Message.php:198
+ Here is the call graph for this function:

◆ registerMediaTypeParser()

Slim\Http\Request::registerMediaTypeParser (   $mediaType,
callable  $callable 
)

Register media type parser.

Note: This method is not part of the PSR-7 standard.

Parameters
string$mediaTypeA HTTP media type (excluding content-type params).
callable$callableA callable that returns parsed contents for media type.

Definition at line 1119 of file Request.php.

References string.

Referenced by Slim\Http\Request\__construct().

1120  {
1121  if ($callable instanceof Closure) {
1122  $callable = $callable->bindTo($this);
1123  }
1124  $this->bodyParsers[(string)$mediaType] = $callable;
1125  }
Add rich text string
+ Here is the caller graph for this function:

◆ reparseBody()

Slim\Http\Request::reparseBody ( )

Force Body to be parsed again.

Note: This method is not part of the PSR-7 standard.

Returns
$this

Definition at line 1102 of file Request.php.

1103  {
1104  $this->bodyParsed = false;
1105 
1106  return $this;
1107  }

◆ withAttribute()

Slim\Http\Request::withAttribute (   $name,
  $value 
)

Return an instance with the specified derived request attribute.

This method allows setting a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated attribute.

See also
getAttributes()
Parameters
string$nameThe attribute name.
mixed$valueThe value of the attribute.
Returns
static

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 948 of file Request.php.

References $name.

949  {
950  $clone = clone $this;
951  $clone->attributes->set($name, $value);
952 
953  return $clone;
954  }
if($format !==null) $name
Definition: metadata.php:146

◆ withAttributes()

Slim\Http\Request::withAttributes ( array  $attributes)

Create a new instance with the specified derived request attributes.

Note: This method is not part of the PSR-7 standard.

This method allows setting all new derived request attributes as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the updated attributes.

Parameters
array$attributesNew attributes
Returns
static

Definition at line 971 of file Request.php.

972  {
973  $clone = clone $this;
974  $clone->attributes = new Collection($attributes);
975 
976  return $clone;
977  }

◆ withCookieParams()

Slim\Http\Request::withCookieParams ( array  $cookies)

Return an instance with the specified cookies.

The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST be compatible with the structure of $_COOKIE. Typically, this data will be injected at instantiation.

This method MUST NOT update the related Cookie header of the request instance, nor related values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated cookie values.

Parameters
array$cookiesArray of key/value pairs representing cookies.
Returns
static

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 750 of file Request.php.

References Slim\Http\Request\$cookies.

751  {
752  $clone = clone $this;
753  $clone->cookies = $cookies;
754 
755  return $clone;
756  }

◆ withMethod()

Slim\Http\Request::withMethod (   $method)

Return an instance with the provided HTTP method.

While HTTP method names are typically all uppercase characters, HTTP method names are case-sensitive and thus implementations SHOULD NOT modify the given string.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request method.

Parameters
string$methodCase-sensitive method.
Returns
static
Exceptions

Implements Psr\Http\Message\RequestInterface.

Definition at line 323 of file Request.php.

References Slim\Http\Request\$method, and Slim\Http\Request\filterMethod().

324  {
325  $method = $this->filterMethod($method);
326  $clone = clone $this;
327  $clone->originalMethod = $method;
328  $clone->method = $method;
329 
330  return $clone;
331  }
filterMethod($method)
Validate the HTTP method.
Definition: Request.php:340
+ Here is the call graph for this function:

◆ withoutAttribute()

Slim\Http\Request::withoutAttribute (   $name)

Return an instance that removes the specified derived request attribute.

This method allows removing a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the attribute.

See also
getAttributes()
Parameters
string$nameThe attribute name.
Returns
static

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 993 of file Request.php.

References $name.

994  {
995  $clone = clone $this;
996  $clone->attributes->remove($name);
997 
998  return $clone;
999  }
if($format !==null) $name
Definition: metadata.php:146

◆ withParsedBody()

Slim\Http\Request::withParsedBody (   $data)

Return an instance with the specified body parameters.

These MAY be injected during instantiation.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, use this method ONLY to inject the contents of $_POST.

The data IS NOT REQUIRED to come from $_POST, but MUST be the results of deserializing the request body content. Deserialization/parsing returns structured data, and, as such, this method ONLY accepts arrays or objects, or a null value if nothing was available to parse.

As an example, if content negotiation determines that the request data is a JSON payload, this method could be used to create a request instance with the deserialized parameters.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
null | array | object$dataThe deserialized body data. This will typically be in an array or object.
Returns
static
Exceptions

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 1083 of file Request.php.

References $data.

1084  {
1085  if (!is_null($data) && !is_object($data) && !is_array($data)) {
1086  throw new InvalidArgumentException('Parsed body value must be an array, an object, or null');
1087  }
1088 
1089  $clone = clone $this;
1090  $clone->bodyParsed = $data;
1091 
1092  return $clone;
1093  }

◆ withQueryParams()

Slim\Http\Request::withQueryParams ( array  $query)

Return an instance with the specified query string arguments.

These values SHOULD remain immutable over the course of the incoming request. They MAY be injected during instantiation, such as from PHP's $_GET superglobal, or MAY be derived from some other value such as the URI. In cases where the arguments are parsed from the URI, the data MUST be compatible with what PHP's parse_str() would return for purposes of how duplicate query parameters are handled, and how nested sets are handled.

Setting query string arguments MUST NOT change the URI stored by the request, nor the values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated query string arguments.

Parameters
array$queryArray of query string arguments, typically from $_GET.
Returns
static

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 811 of file Request.php.

References $query.

812  {
813  $clone = clone $this;
814  $clone->queryParams = $query;
815 
816  return $clone;
817  }
$query

◆ withRequestTarget()

Slim\Http\Request::withRequestTarget (   $requestTarget)

Return an instance with the specific request-target.

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request target.

(for the various request-target forms allowed in request messages) mixed $requestTarget static InvalidArgumentException if the request target is invalid

Implements Psr\Http\Message\RequestInterface.

Definition at line 531 of file Request.php.

References Slim\Http\Request\$requestTarget.

532  {
533  if (preg_match('#\s#', $requestTarget)) {
534  throw new InvalidArgumentException(
535  'Invalid request target provided; must be a string and cannot contain whitespace'
536  );
537  }
538  $clone = clone $this;
539  $clone->requestTarget = $requestTarget;
540 
541  return $clone;
542  }

◆ withUploadedFiles()

Slim\Http\Request::withUploadedFiles ( array  $uploadedFiles)

Create a new instance with the specified uploaded files.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
array$uploadedFilesAn array tree of UploadedFileInterface instances.
Returns
static
Exceptions

Implements Psr\Http\Message\ServerRequestInterface.

Definition at line 851 of file Request.php.

References Slim\Http\Request\$uploadedFiles.

852  {
853  $clone = clone $this;
854  $clone->uploadedFiles = $uploadedFiles;
855 
856  return $clone;
857  }

◆ withUri()

Slim\Http\Request::withUri ( UriInterface  $uri,
  $preserveHost = false 
)

Returns an instance with the provided URI.

This method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • If the the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request.
  • If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request.
  • If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new UriInterface instance.

UriInterface $uri New request URI to use. bool $preserveHost Preserve the original state of the Host header. static

Implements Psr\Http\Message\RequestInterface.

Definition at line 588 of file Request.php.

References Slim\Http\Request\$uri, Slim\Http\Message\getHeaderLine(), Psr\Http\Message\UriInterface\getHost(), and Slim\Http\Message\hasHeader().

589  {
590  $clone = clone $this;
591  $clone->uri = $uri;
592 
593  if (!$preserveHost) {
594  if ($uri->getHost() !== '') {
595  $clone->headers->set('Host', $uri->getHost());
596  }
597  } else {
598  if ($uri->getHost() !== '' && (!$this->hasHeader('Host') || $this->getHeaderLine('Host') === '')) {
599  $clone->headers->set('Host', $uri->getHost());
600  }
601  }
602 
603  return $clone;
604  }
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.
Definition: Message.php:198
hasHeader($name)
Checks if a header exists by the given case-insensitive name.
Definition: Message.php:155
+ Here is the call graph for this function:

Field Documentation

◆ $attributes

Slim\Http\Request::$attributes
protected

Definition at line 89 of file Request.php.

Referenced by Slim\Http\Request\__clone().

◆ $bodyParsed

Slim\Http\Request::$bodyParsed = false
protected

Definition at line 96 of file Request.php.

Referenced by Slim\Http\Request\getParsedBody().

◆ $bodyParsers

Slim\Http\Request::$bodyParsers = []
protected

Definition at line 103 of file Request.php.

◆ $cookies

◆ $method

◆ $originalMethod

Slim\Http\Request::$originalMethod
protected

Definition at line 47 of file Request.php.

Referenced by Slim\Http\Request\getMethod(), and Slim\Http\Request\getOriginalMethod().

◆ $queryParams

Slim\Http\Request::$queryParams
protected

Definition at line 68 of file Request.php.

Referenced by Slim\Http\Request\getQueryParams().

◆ $requestTarget

Slim\Http\Request::$requestTarget
protected

◆ $serverParams

◆ $uploadedFiles

◆ $uri

◆ $validMethods

Slim\Http\Request::$validMethods
protected
Initial value:
= [
'CONNECT' => 1

Definition at line 118 of file Request.php.


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