140 $method = $environment[
'REQUEST_METHOD'];
151 in_array(
$request->getMediaType(), [
'application/x-www-form-urlencoded',
'multipart/form-data'])
185 $this->originalMethod =
$method;
196 if (isset($serverParams[
'SERVER_PROTOCOL'])) {
197 $this->protocolVersion = str_replace(
'HTTP/',
'', $serverParams[
'SERVER_PROTOCOL']);
200 if (!$this->headers->has(
'Host') && $this->uri->getHost() !==
'') {
201 $port = $this->uri->getPort() ?
":{$this->uri->getPort()}" :
'';
203 $this->headers->set(
'Host', $this->uri->getHost() . $port);
215 $backup = libxml_disable_entity_loader(
true);
216 $backup_errors = libxml_use_internal_errors(
true);
218 libxml_disable_entity_loader($backup);
219 libxml_clear_errors();
220 libxml_use_internal_errors($backup_errors);
228 $backup = libxml_disable_entity_loader(
true);
229 $backup_errors = libxml_use_internal_errors(
true);
231 libxml_disable_entity_loader($backup);
232 libxml_clear_errors();
233 libxml_use_internal_errors($backup_errors);
275 if ($this->method === null) {
277 $customMethod = $this->
getHeaderLine(
'X-Http-Method-Override');
281 } elseif ($this->originalMethod ===
'POST') {
283 if ($overrideMethod !== null) {
284 $this->method = $overrideMethod;
326 $clone = clone $this;
327 $clone->originalMethod =
$method;
348 'Unsupported HTTP method; must be a string, received %s',
354 if (preg_match(
"/^[!#$%&'*+.^_`|~0-9a-z-]+$/i",
$method) !== 1) {
467 return $this->
getHeaderLine(
'X-Requested-With') ===
'XMLHttpRequest';
492 if ($this->requestTarget) {
496 if ($this->uri === null) {
500 $basePath = $this->uri->getBasePath();
501 $path = $this->uri->getPath();
504 $query = $this->uri->getQuery();
508 $this->requestTarget =
$path;
535 'Invalid request target provided; must be a string and cannot contain whitespace' 538 $clone = clone $this;
590 $clone = clone $this;
593 if (!$preserveHost) {
595 $clone->headers->set(
'Host', $uri->
getHost());
599 $clone->headers->set(
'Host', $uri->
getHost());
631 $contentTypeParts = preg_split(
'/\s*[;,]\s*/',
$contentType);
633 return strtolower($contentTypeParts[0]);
649 $contentTypeParams = [];
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];
659 return $contentTypeParams;
672 if (isset($mediaTypeParams[
'charset'])) {
673 return $mediaTypeParams[
'charset'];
688 $result = $this->headers->get(
'Content-Length');
752 $clone = clone $this;
776 if (is_array($this->queryParams)) {
780 if ($this->uri === null) {
813 $clone = clone $this;
814 $clone->queryParams =
$query;
853 $clone = clone $this;
910 return $this->attributes->all();
950 $clone = clone $this;
951 $clone->attributes->set(
$name, $value);
973 $clone = clone $this;
974 $clone->attributes =
new Collection($attributes);
995 $clone = clone $this;
996 $clone->attributes->remove(
$name);
1023 if ($this->bodyParsed !==
false) {
1034 $parts = explode(
'+', $mediaType);
1035 if (count($parts) >= 2) {
1036 $mediaType =
'application/' . $parts[count($parts)-1];
1039 if (isset($this->bodyParsers[$mediaType]) ===
true) {
1041 $parsed = $this->bodyParsers[$mediaType](
$body);
1043 if (!is_null($parsed) && !is_object($parsed) && !is_array($parsed)) {
1045 'Request body media type parser return value must be an array, an object, or null' 1048 $this->bodyParsed = $parsed;
1089 $clone = clone $this;
1090 $clone->bodyParsed =
$data;
1104 $this->bodyParsed =
false;
1121 if ($callable instanceof
Closure) {
1122 $callable = $callable->bindTo($this);
1124 $this->bodyParsers[(string)$mediaType] = $callable;
1146 if (is_array($postParams) && isset($postParams[
$key])) {
1148 } elseif (is_object($postParams) && property_exists($postParams, $key)) {
1150 } elseif (isset($getParams[$key])) {
1171 if (is_array($postParams) && isset($postParams[
$key])) {
1173 } elseif (is_object($postParams) && property_exists($postParams, $key)) {
1194 if (isset($getParams[
$key])) {
1219 foreach ($only as
$key) {
1220 if (array_key_exists($key,
$params)) {
getAttributes()
Retrieve attributes derived from the request.
__construct( $method, UriInterface $uri, HeadersInterface $headers, array $cookies, array $serverParams, StreamInterface $body, array $uploadedFiles=[])
Create new HTTP request.
getBody()
Gets the body of the message.
Representation of an incoming, server-side HTTP request.
isHead()
Is this a HEAD request?
getHost()
Retrieve the host component of the URI.
withCookieParams(array $cookies)
Return an instance with the specified cookies.
isOptions()
Is this a OPTIONS request?
withoutAttribute($name)
Return an instance that removes the specified derived request attribute.
isPatch()
Is this a PATCH request?
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.
getCookieParam($key, $default=null)
Fetch cookie value from cookies sent by the client to the server.
foreach($paths as $path) $request
Abstract message (base class for Request and Response)
getParsedBody()
Retrieve any parameters provided in the request body.
getMethod()
Retrieves the HTTP method of the request.
isXhr()
Is this an XHR request?
getCookieParams()
Retrieve cookies.
static createFromEnvironment(Environment $env)
Create new Uri from environment.
Value object representing a URI.
getParsedBodyParam($key, $default=null)
Fetch parameter value from request body.
withAttributes(array $attributes)
Create a new instance with the specified derived request attributes.
isMethod($method)
Does this request use a given method?
withRequestTarget($requestTarget)
Return an instance with the specific request-target.
withUri(UriInterface $uri, $preserveHost=false)
Returns an instance with the provided URI.
isPost()
Is this a POST request?
getQueryParams()
Retrieve query string arguments.
reparseBody()
Force Body to be parsed again.
getParam($key, $default=null)
Fetch request parameter value from body or query string (in that order).
__clone()
This method is applied to the cloned object after PHP performs an initial shallow-copy.
getServerParam($key, $default=null)
Retrieve a server parameter.
isDelete()
Is this a DELETE request?
getRequestTarget()
Retrieves the message's request target.
static parseHeader($header)
Parse HTTP request Cookie: header and extract into a PHP associative array.
getOriginalMethod()
Get the original HTTP method (ignore override).
getContentType()
Get request content type.
Slim Framework (https://slimframework.com)
getContentLength()
Get request content length, if known.
isPut()
Is this a PUT request?
getMediaTypeParams()
Get request media type params, if known.
all()
Get all items in collection.
hasHeader($name)
Checks if a header exists by the given case-insensitive name.
getServerParams()
Retrieve server parameters.
static createFromEnvironment(Environment $environment)
Create new HTTP request with data extracted from the application Environment object.
Provides a PSR-7 implementation of a reusable raw request body.
registerMediaTypeParser($mediaType, callable $callable)
Register media type parser.
filterMethod($method)
Validate the HTTP method.
getHeader($name)
Retrieves a message header value by the given case-insensitive name.
getParams(array $only=null)
Fetch associative array of body and query string parameters.
isGet()
Is this a GET request?
withAttribute($name, $value)
Return an instance with the specified derived request attribute.
withParsedBody($data)
Return an instance with the specified body parameters.
getMediaType()
Get request media type, if known.
getUri()
Retrieves the URI instance.
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
getAttribute($name, $default=null)
Retrieve a single derived request attribute.
static createFromEnvironment(Environment $env)
Create a normalized tree of UploadedFile instances from the Environment.
getUploadedFiles()
Retrieve normalized file upload data.
withMethod($method)
Return an instance with the provided HTTP method.
getQueryParam($key, $default=null)
Fetch parameter value from query string.
withUploadedFiles(array $uploadedFiles)
Create a new instance with the specified uploaded files.
getContentCharset()
Get request content character set, if known.
withQueryParams(array $query)
Return an instance with the specified query string arguments.