W3cubDocs

/CakePHP 4.1

Class ServerRequest

A class that helps wrap Request information and particulars about a single request.

Provides methods commonly used to introspect on the request headers and request body.

Namespace: Cake\Http

Properties summary

  • $_detectorCache protected
    array

    Instance cache for results of is(something) calls

  • $_detectors protected static
    (array|callable)[]

    The built in detectors used with is() can be modified with addDetector().

  • $_environment protected
    array

    Array of environment data.

  • $attributes protected
    array

    Store the additional attributes attached to the request.

  • $base protected
    string

    Base URL path.

  • $cookies protected
    array

    Array of cookie data.

  • $data protected
    array|object|null

    Array of POST data. Will contain form data as well as uploaded files.

  • array

    A list of propertes that emulated by the PSR7 attribute methods.

  • $params protected
    array

    Array of parameters parsed from the URL.

  • $protocol protected
    string|null

    The HTTP protocol version used.

  • $query protected
    array

    Array of query string arguments

  • $requestTarget protected
    string|null

    The request target if overridden

  • $session protected
    \Cake\Http\Session

    Instance of a Session object relative to this request

  • $stream protected
    \Psr\Http\Message\StreamInterface

    Request body stream. Contains php://input unless input constructor option is used.

  • $trustProxy public
    bool

    Whether or not to trust HTTP_X headers set by most load balancers.

  • $trustedProxies protected
    string[]

    Trusted proxies list

  • $uploadedFiles protected
    array

    Array of Psr\Http\Message\UploadedFileInterface objects.

  • $uri protected
    \Psr\Http\Message\UriInterface

    Uri instance

  • $webroot protected
    string

    webroot path segment for the request.

Method Summary

  • __call() public

    Missing method handler, handles wrapping older style isAjax() type methods

  • __construct() public

    Create a new request object.

  • _acceptHeaderDetector() protected

    Detects if a specific accept header is present.

  • _environmentDetector() protected

    Detects if a specific environment variable is present.

  • _headerDetector() protected

    Detects if a specific header is present.

  • _is() protected

    Worker for the public is() function

  • _paramDetector() protected

    Detects if a specific request parameter is present.

  • _parseAcceptWithQualifier() protected

    Parse Accept* headers with qualifier options.

  • _setConfig() protected

    Process the config/settings data into properties.

  • acceptLanguage() public

    Get the languages accepted by the client, or check if a specific language is accepted.

  • accepts() public

    Find out which content types the client accepts or check if they accept a particular type of content.

  • addDetector() public static

    Add a new detector to the list of detectors that a request can use.

  • allowMethod() public

    Allow only certain HTTP request methods, if the request method does not match a 405 error will be shown and the required "Allow" response header will be set.

  • clearDetectorCache() public

    Clears the instance detector cache, used by the is() function

  • clientIp() public

    Get the IP the client is using, or says they are using.

  • contentType() public

    Get the content type used in this request.

  • domain() public

    Get the domain name and include $tldLength segments of the tld.

  • getAttribute() public

    Read an attribute from the request, or get the default

  • getAttributes() public

    Get all the attributes in the request.

  • getBody() public

    Gets the body of the message.

  • getCookie() public

    Read cookie data from the request's cookie data.

  • getCookieCollection() public

    Get a cookie collection based on the request's cookies

  • getCookieParams() public

    Get all the cookie data from the request.

  • getData() public

    Provides a safe accessor for request data. Allows you to use Hash::get() compatible paths.

  • getEnv() public

    Get a value from the request's environment data.

  • getHeader() public

    Get a single header from the request.

  • getHeaderLine() public

    Get a single header as a string from the request.

  • getHeaders() public

    Get all headers in the request.

  • getMethod() public

    Get the HTTP method used for this request.

  • getParam() public

    Safely access the values in $this->params.

  • getParsedBody() public

    Get the parsed request body data.

  • getPath() public

    Get the path of current request.

  • getProtocolVersion() public

    Retrieves the HTTP protocol version as a string.

  • getQuery() public

    Read a specific query value or dotted path.

  • getQueryParams() public

    Get all the query parameters in accordance to the PSR-7 specifications. To read specific query values use the alternative getQuery() method.

  • getRequestTarget() public

    Retrieves the request's target.

  • getServerParams() public

    Get all the server environment parameters.

  • getSession() public

    Returns the instance of the Session object for this request

  • getTrustedProxies() public

    Get trusted proxies

  • getUploadedFile() public

    Get the uploaded file from a dotted path.

  • getUploadedFiles() public

    Get the array of uploaded files from the request.

  • getUri() public

    Retrieves the URI instance.

  • hasHeader() public

    Check if a header is set in the request.

  • host() public

    Get the host that the request was handled on.

  • input() public

    Read data from php://input. Useful when interacting with XML or JSON request body content.

  • is() public

    Check whether or not a Request is a certain type.

  • isAll() public

    Check that a request matches all the given types.

  • normalizeHeaderName() protected

    Normalize a header name into the SERVER version.

  • parseAccept() public

    Parse the HTTP_ACCEPT header and return a sorted array with content types as the keys, and pref values as the values.

  • port() public

    Get the port the request was handled on.

  • processUrlOption() protected

    Set environment vars based on url option to facilitate UriInterface instance generation.

  • referer() public

    Returns the referer that referred this request.

  • scheme() public

    Get the current url scheme used for the request.

  • setTrustedProxies() public

    register trusted proxies

  • subdomains() public

    Get the subdomains for a host.

  • validateUploadedFiles() protected

    Recursively validate uploaded file data.

  • withAddedHeader() public

    Get a modified request with the provided header.

  • withAttribute() public

    Return an instance with the specified request attribute.

  • withBody() public

    Return an instance with the specified message body.

  • withCookieCollection() public

    Replace the cookies in the request with those contained in the provided CookieCollection.

  • withCookieParams() public

    Replace the cookies and get a new request instance.

  • withData() public

    Update the request with a new request data element.

  • withEnv() public

    Update the request with a new environment data element.

  • withHeader() public

    Get a modified request with the provided header.

  • withMethod() public

    Update the request method and get a new instance.

  • withParam() public

    Update the request with a new routing parameter

  • withParsedBody() public

    Update the parsed body and get a new instance.

  • withProtocolVersion() public

    Return an instance with the specified HTTP protocol version.

  • withQueryParams() public

    Update the query string data and get a new instance.

  • withRequestTarget() public

    Create a new instance with a specific request-target.

  • withUploadedFiles() public

    Update the request replacing the files, and creating a new instance.

  • withUri() public

    Return an instance with the specified uri

  • withoutAttribute() public

    Return an instance without the specified request attribute.

  • withoutData() public

    Update the request removing a data element.

  • withoutHeader() public

    Get a modified request without a provided header.

Method Detail

__call() public

__call(string $name, array $params)

Missing method handler, handles wrapping older style isAjax() type methods

Parameters

string $name

The method called

array $params

Array of parameters for the method call

Returns

mixed

Throws

BadMethodCallException
when an invalid method is called.

__construct() public

__construct(array $config)

Create a new request object.

You can supply the data as either an array or as a string. If you use a string you can only supply the URL for the request. Using an array will let you provide the following keys:

  • post POST data or non query string data
  • query Additional data from the query string.
  • files Uploaded files in a normalized structure, with each leaf an instance of UploadedFileInterface.
  • cookies Cookies for this request.
  • environment $_SERVER and $_ENV data.
  • url The URL without the base path for the request.
  • uri The PSR7 UriInterface object. If null, one will be created from url or environment.
  • base The base URL for the request.
  • webroot The webroot directory for the request.
  • input The data that would come from php://input this is useful for simulating requests with put, patch or delete data.
  • session An instance of a Session object

Parameters

array $config optional

An array of request data to create a request with.

_acceptHeaderDetector() protected

_acceptHeaderDetector(array $detect)

Detects if a specific accept header is present.

Parameters

array $detect

Detector options array.

Returns

bool

Whether or not the request is the type you are checking.

_environmentDetector() protected

_environmentDetector(array $detect)

Detects if a specific environment variable is present.

Parameters

array $detect

Detector options array.

Returns

bool

Whether or not the request is the type you are checking.

_headerDetector() protected

_headerDetector(array $detect)

Detects if a specific header is present.

Parameters

array $detect

Detector options array.

Returns

bool

Whether or not the request is the type you are checking.

_is() protected

_is(string $type, array $args)

Worker for the public is() function

Parameters

string $type

The type of request you want to check.

array $args

Array of custom detector arguments.

Returns

bool

Whether or not the request is the type you are checking.

_paramDetector() protected

_paramDetector(array $detect)

Detects if a specific request parameter is present.

Parameters

array $detect

Detector options array.

Returns

bool

Whether or not the request is the type you are checking.

_parseAcceptWithQualifier() protected

_parseAcceptWithQualifier(string $header)

Parse Accept* headers with qualifier options.

Only qualifiers will be extracted, any other accept extensions will be discarded as they are not frequently used.

Parameters

string $header

Header to parse.

Returns

array

_setConfig() protected

_setConfig(array $config)

Process the config/settings data into properties.

Parameters

array $config

The config data to use.

acceptLanguage() public

acceptLanguage(?string $language)

Get the languages accepted by the client, or check if a specific language is accepted.

Get the list of accepted languages:

\Cake\Http\ServerRequest::acceptLanguage();

Check if a specific language is accepted:

\Cake\Http\ServerRequest::acceptLanguage('es-es');

Parameters

string|null $language optional

The language to test.

Returns

array|bool

If a $language is provided, a boolean. Otherwise the array of accepted languages.

accepts() public

accepts(?string $type)

Find out which content types the client accepts or check if they accept a particular type of content.

Get all types:

$this->request->accepts();

Check for a single type:

$this->request->accepts('application/json');

This method will order the returned content types by the preference values indicated by the client.

Parameters

string|null $type optional

The content type to check for. Leave null to get all types a client accepts.

Returns

array|bool

Either an array of all the types the client accepts or a boolean if they accept the provided type.

addDetector() public static

addDetector(string $name, mixed $callable)

Add a new detector to the list of detectors that a request can use.

There are several different types of detectors that can be set.

Callback comparison

Callback detectors allow you to provide a callable to handle the check. The callback will receive the request object as its only parameter.

addDetector('custom', function ($request) { //Return a boolean });

Environment value comparison

An environment value comparison, compares a value fetched from env() to a known value the environment value is equality checked against the provided value.

addDetector('post', ['env' => 'REQUEST_METHOD', 'value' => 'POST']);

Request parameter comparison

Allows for custom detectors on the request parameters.

addDetector('admin', ['param' => 'prefix', 'value' => 'admin']);

Accept comparison

Allows for detector to compare against Accept header value.

addDetector('csv', ['accept' => 'text/csv']);

Header comparison

Allows for one or more headers to be compared.

addDetector('fancy', ['header' => ['X-Fancy' => 1]);

The param, env and comparison types allow the following value comparison options:

Pattern value comparison

Pattern value comparison allows you to compare a value fetched from env() to a regular expression.

addDetector('iphone', ['env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i']);

Option based comparison

Option based comparisons use a list of options to create a regular expression. Subsequent calls to add an already defined options detector will merge the options.

addDetector('mobile', ['env' => 'HTTP_USER_AGENT', 'options' => ['Fennec']]);

You can also make compare against multiple values using the options key. This is useful when you want to check if a request value is in a list of options.

addDetector('extension', ['param' => '_ext', 'options' => ['pdf', 'csv']]

Parameters

string $name

The name of the detector.

callable|array $callable

A callable or options array for the detector definition.

allowMethod() public

allowMethod(mixed $methods)

Allow only certain HTTP request methods, if the request method does not match a 405 error will be shown and the required "Allow" response header will be set.

Example:

$this->request->allowMethod('post'); or $this->request->allowMethod(['post', 'delete']);

If the request would be GET, response header "Allow: POST, DELETE" will be set and a 405 error will be returned.

Parameters

string|array $methods

Allowed HTTP request methods.

Returns

true

Throws

Cake\Http\Exception\MethodNotAllowedException

clearDetectorCache() public

clearDetectorCache()

Clears the instance detector cache, used by the is() function

clientIp() public

clientIp()

Get the IP the client is using, or says they are using.

Returns

string

The client IP.

contentType() public

contentType()

Get the content type used in this request.

Returns

string|null

domain() public

domain(int $tldLength)

Get the domain name and include $tldLength segments of the tld.

Parameters

int $tldLength optional

Number of segments your tld contains. For example: example.com contains 1 tld. While example.co.uk contains 2.

Returns

string

Domain name without subdomains.

getAttribute() public

getAttribute(mixed $name, mixed $default)

Read an attribute from the request, or get the default

Parameters

string $name

The attribute name.

mixed|null $default optional

The default value if the attribute has not been set.

Returns

mixed

getAttributes() public

getAttributes()

Get all the attributes in the request.

This will include the params, webroot, base, and here attributes that CakePHP provides.

Returns

array

getBody() public

getBody()

Gets the body of the message.

Returns

\Psr\Http\Message\StreamInterface

Returns the body as a stream.

getCookie() public

getCookie(string $key, mixed $default)

Read cookie data from the request's cookie data.

Parameters

string $key

The key or dotted path you want to read.

string|array|null $default optional

The default value if the cookie is not set.

Returns

string|array|null

Either the cookie value, or null if the value doesn't exist.

getCookieCollection() public

getCookieCollection()

Get a cookie collection based on the request's cookies

The CookieCollection lets you interact with request cookies using \Cake\Http\Cookie\Cookie objects and can make converting request cookies into response cookies easier.

This method will create a new cookie collection each time it is called. This is an optimization that allows fewer objects to be allocated until the more complex CookieCollection is needed. In general you should prefer getCookie() and getCookieParams() over this method. Using a CookieCollection is ideal if your cookies contain complex JSON encoded data.

Returns

\Cake\Http\Cookie\CookieCollection

getCookieParams() public

getCookieParams()

Get all the cookie data from the request.

Returns

array

An array of cookie data.

getData() public

getData(?string $name, mixed $default)

Provides a safe accessor for request data. Allows you to use Hash::get() compatible paths.

Reading values.

// get all data
$request->getData();

// Read a specific field.
$request->getData('Post.title');

// With a default value.
$request->getData('Post.not there', 'default value');

When reading values you will get null for keys/values that do not exist.

Developers are encouraged to use getParsedBody() if they need the whole data array, as it is PSR-7 compliant, and this method is not. Using Hash::get() you can also get single params.

PSR-7 Alternative

$value = Hash::get($request->getParsedBody(), 'Post.id');

Parameters

string|null $name optional

Dot separated name of the value to read. Or null to read all data.

mixed $default optional

The default data.

Returns

mixed

The value being read.

getEnv() public

getEnv(string $key, ?string $default)

Get a value from the request's environment data.

Fallback to using env() if the key is not set in the $environment property.

Parameters

string $key

The key you want to read from.

string|null $default optional

Default value when trying to retrieve an environment variable's value that does not exist.

Returns

string|null

Either the environment value, or null if the value doesn't exist.

getHeader() public

getHeader(mixed $name)

Get a single header from the request.

Return the header value as an array. If the header is not present an empty array will be returned.

Parameters

string $name

The header you want to get (case-insensitive)

Returns

string[]

An associative array of headers and their values. If the header doesn't exist, an empty array will be returned.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getHeaderLine() public

getHeaderLine(mixed $name)

Get a single header as a string from the request.

Parameters

string $name

The header you want to get (case-insensitive)

Returns

string

Header values collapsed into a comma separated string.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getHeaders() public

getHeaders()

Get all headers in the request.

Returns an associative array where the header names are the keys and the values are a list of header values.

While header names are not case-sensitive, getHeaders() will normalize the headers.

Returns

string[][]

An associative array of headers and their values.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getMethod() public

getMethod()

Get the HTTP method used for this request.

There are a few ways to specify a method.

  • If your client supports it you can use native HTTP methods.
  • You can set the HTTP-X-Method-Override header.
  • You can submit an input with the name _method

Any of these 3 approaches can be used to set the HTTP method used by CakePHP internally, and will effect the result of this method.

Returns

string

The name of the HTTP method used.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getParam() public

getParam(string $name, mixed $default)

Safely access the values in $this->params.

Parameters

string $name

The name or dotted path to parameter.

mixed $default optional

The default value if $name is not set. Default null.

Returns

mixed

getParsedBody() public

getParsedBody()

Get the parsed request body data.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, this will be the post data. For other content types, it may be the deserialized request body.

Returns

array|object|null

The deserialized body parameters, if any. These will typically be an array.

getPath() public

getPath()

Get the path of current request.

Returns

string

getProtocolVersion() public

getProtocolVersion()

Retrieves the HTTP protocol version as a string.

Returns

string

HTTP protocol version.

getQuery() public

getQuery(?string $name, mixed $default)

Read a specific query value or dotted path.

Developers are encouraged to use getQueryParams() if they need the whole query array, as it is PSR-7 compliant, and this method is not. Using Hash::get() you can also get single params.

PSR-7 Alternative

$value = Hash::get($request->getQueryParams(), 'Post.id');

Parameters

string|null $name optional

The name or dotted path to the query param or null to read all.

mixed $default optional

The default value if the named parameter is not set, and $name is not null.

Returns

array|string|null

Query data.

See Also

\Cake\Http\ServerRequest::getQueryParams()

getQueryParams() public

getQueryParams()

Get all the query parameters in accordance to the PSR-7 specifications. To read specific query values use the alternative getQuery() method.

Returns

array

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getRequestTarget() public

getRequestTarget()

Retrieves the request's target.

Retrieves the message's request-target either as it was requested, or as set with withRequestTarget(). By default this will return the application relative path without base directory, and the query string defined in the SERVER environment.

Returns

string

getServerParams() public

getServerParams()

Get all the server environment parameters.

Read all of the 'environment' or 'server' data that was used to create this request.

Returns

array

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

getSession() public

getSession()

Returns the instance of the Session object for this request

Returns

\Cake\Http\Session

getTrustedProxies() public

getTrustedProxies()

Get trusted proxies

Returns

string[]

getUploadedFile() public

getUploadedFile(string $path)

Get the uploaded file from a dotted path.

Parameters

string $path

The dot separated path to the file you want.

Returns

\Psr\Http\Message\UploadedFileInterface|null

getUploadedFiles() public

getUploadedFiles()

Get the array of uploaded files from the request.

Returns

array

getUri() public

getUri()

Retrieves the URI instance.

Returns

\Psr\Http\Message\UriInterface

Returns a UriInterface instance representing the URI of the request.

hasHeader() public

hasHeader(mixed $name)

Check if a header is set in the request.

Parameters

string $name

The header you want to get (case-insensitive)

Returns

bool

Whether or not the header is defined.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

host() public

host()

Get the host that the request was handled on.

Returns

string|null

input() public

input(?callable $callback, mixed ...$args)

Read data from php://input. Useful when interacting with XML or JSON request body content.

Getting input with a decoding function:

$this->request->input('json_decode');

Getting input using a decoding function, and additional params:

$this->request->input('Xml::build', ['return' => 'DOMDocument']);

Any additional parameters are applied to the callback in the order they are given.

Parameters

callable|null $callback optional

A decoding callback that will convert the string data to another representation. Leave empty to access the raw input data. You can also supply additional parameters for the decoding callback using var args, see above.

mixed ...$args

The additional arguments

Returns

mixed

The decoded/processed request data.

is() public

is(mixed $type, mixed ...$args)

Check whether or not a Request is a certain type.

Uses the built in detection rules as well as additional rules defined with Cake\Http\ServerRequest::addDetector(). Any detector can be called as is($type) or is$Type().

Parameters

string|string[] $type

The type of request you want to check. If an array this method will return true if the request matches any type.

string ...$args

List of arguments

Returns

bool

Whether or not the request is the type you are checking.

isAll() public

isAll(array $types)

Check that a request matches all the given types.

Allows you to test multiple types and union the results. See Request::is() for how to add additional types and the built-in types.

Parameters

string[] $types

The types to check.

Returns

bool

Success.

See Also

\Cake\Http\ServerRequest::is()

normalizeHeaderName() protected

normalizeHeaderName(string $name)

Normalize a header name into the SERVER version.

Parameters

string $name

The header name.

Returns

string

The normalized header name.

parseAccept() public

parseAccept()

Parse the HTTP_ACCEPT header and return a sorted array with content types as the keys, and pref values as the values.

Generally you want to use Cake\Http\ServerRequest::accept() to get a simple list of the accepted content types.

Returns

array

An array of prefValue => [content/types]

port() public

port()

Get the port the request was handled on.

Returns

string|null

processUrlOption() protected

processUrlOption(array $config)

Set environment vars based on url option to facilitate UriInterface instance generation.

query option is also updated based on URL's querystring.

Parameters

array $config

Config array.

Returns

array

Update config.

referer() public

referer(bool $local)

Returns the referer that referred this request.

Parameters

bool $local optional

Attempt to return a local address. Local addresses do not contain hostnames.

Returns

string|null

The referring address for this request or null.

scheme() public

scheme()

Get the current url scheme used for the request.

e.g. 'http', or 'https'

Returns

string|null

The scheme used for the request.

setTrustedProxies() public

setTrustedProxies(array $proxies)

register trusted proxies

Parameters

string[] $proxies

ips list of trusted proxies

subdomains() public

subdomains(int $tldLength)

Get the subdomains for a host.

Parameters

int $tldLength optional

Number of segments your tld contains. For example: example.com contains 1 tld. While example.co.uk contains 2.

Returns

string[]

An array of subdomains.

validateUploadedFiles() protected

validateUploadedFiles(array $uploadedFiles, string $path)

Recursively validate uploaded file data.

Parameters

array $uploadedFiles

The new files array to validate.

string $path

The path thus far.

Throws

InvalidArgumentException
If any leaf elements are not valid files.

withAddedHeader() public

withAddedHeader(mixed $name, mixed $value)

Get a modified request with the provided header.

Existing header values will be retained. The provided value will be appended into the existing values.

Parameters

string $name

The header name.

string|array $value

The header value

Returns

static

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

withAttribute() public

withAttribute(mixed $name, mixed $value)

Return an instance with the specified request attribute.

Parameters

string $name

The attribute name.

mixed $value

The value of the attribute.

Returns

static

withBody() public

withBody(\Psr\Http\Message\StreamInterface $body)

Return an instance with the specified message body.

Parameters

\Psr\Http\Message\StreamInterface $body

The new request body

Returns

static

withCookieCollection() public

withCookieCollection(\Cake\Http\Cookie\CookieCollection $cookies)

Replace the cookies in the request with those contained in the provided CookieCollection.

Parameters

\Cake\Http\Cookie\CookieCollection $cookies

The cookie collection

Returns

static

withCookieParams() public

withCookieParams(array $cookies)

Replace the cookies and get a new request instance.

Parameters

array $cookies

The new cookie data to use.

Returns

static

withData() public

withData(string $name, mixed $value)

Update the request with a new request data element.

Returns an updated request object. This method returns a new request object and does not mutate the request in-place.

Use withParsedBody() if you need to replace the all request data.

Parameters

string $name

The dot separated path to insert $value at.

mixed $value

The value to insert into the request data.

Returns

static

withEnv() public

withEnv(string $key, string $value)

Update the request with a new environment data element.

Returns an updated request object. This method returns a new request object and does not mutate the request in-place.

Parameters

string $key

The key you want to write to.

string $value

Value to set

Returns

static

withHeader() public

withHeader(mixed $name, mixed $value)

Get a modified request with the provided header.

Parameters

string $name

The header name.

string|array $value

The header value

Returns

static

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

withMethod() public

withMethod(mixed $method)

Update the request method and get a new instance.

Parameters

string $method

The HTTP method to use.

Returns

static

A new instance with the updated method.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

withParam() public

withParam(string $name, mixed $value)

Update the request with a new routing parameter

Returns an updated request object. This method returns a new request object and does not mutate the request in-place.

Parameters

string $name

The dot separated path to insert $value at.

mixed $value

The value to insert into the the request parameters.

Returns

static

withParsedBody() public

withParsedBody(mixed $data)

Update the parsed body and get a new instance.

Parameters

array|object|null $data

The deserialized body data. This will typically be in an array or object.

Returns

static

withProtocolVersion() public

withProtocolVersion(mixed $version)

Return an instance with the specified HTTP protocol version.

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters

string $version

HTTP protocol version

Returns

static

withQueryParams() public

withQueryParams(array $query)

Update the query string data and get a new instance.

Parameters

array $query

The query string data to use

Returns

static

A new instance with the updated query string data.

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

withRequestTarget() public

withRequestTarget(mixed $target)

Create a new instance with a specific request-target.

You can use this method to overwrite the request target that is inferred from the request's Uri. This also lets you change the request target's form to an absolute-form, authority-form or asterisk-form

Parameters

string $target

The request target.

Returns

static

Links

https://tools.ietf.org/html/rfc7230#section-2.7
(for the various request-target forms allowed in request messages)

withUploadedFiles() public

withUploadedFiles(array $files)

Update the request replacing the files, and creating a new instance.

Parameters

array $files

An array of uploaded file objects.

Returns

static

Throws

InvalidArgumentException
when $files contains an invalid object.

withUri() public

withUri(\Psr\Http\Message\UriInterface $uri, mixed $preserveHost)

Return an instance with the specified uri

Warning Replacing the Uri will not update the base, webroot, and url attributes.

Parameters

\Psr\Http\Message\UriInterface $uri

The new request uri

bool $preserveHost optional

Whether or not the host should be retained.

Returns

static

withoutAttribute() public

withoutAttribute(mixed $name)

Return an instance without the specified request attribute.

Parameters

string $name

The attribute name.

Returns

static

Throws

InvalidArgumentException

withoutData() public

withoutData(string $name)

Update the request removing a data element.

Returns an updated request object. This method returns a new request object and does not mutate the request in-place.

Parameters

string $name

The dot separated path to remove.

Returns

static

withoutHeader() public

withoutHeader(mixed $name)

Get a modified request without a provided header.

Parameters

string $name

The header name to remove.

Returns

static

Links

http://www.php-fig.org/psr/psr-7/
This method is part of the PSR-7 server request interface.

Property Detail

$_detectorCache protected

Instance cache for results of is(something) calls

Type

array

$_detectors protected static

The built in detectors used with is() can be modified with addDetector().

There are several ways to specify a detector, see \Cake\Http\ServerRequest::addDetector() for the various formats and ways to define detectors.

Type

(array|callable)[]

$_environment protected

Array of environment data.

Type

array

$attributes protected

Store the additional attributes attached to the request.

Type

array

$base protected

Base URL path.

Type

string

$cookies protected

Array of cookie data.

Type

array

$data protected

Array of POST data. Will contain form data as well as uploaded files.

In PUT/PATCH/DELETE requests this property will contain the form-urlencoded data.

Type

array|object|null

$emulatedAttributes protected

A list of propertes that emulated by the PSR7 attribute methods.

Type

array

$params protected

Array of parameters parsed from the URL.

Type

array

$protocol protected

The HTTP protocol version used.

Type

string|null

$query protected

Array of query string arguments

Type

array

$requestTarget protected

The request target if overridden

Type

string|null

$session protected

Instance of a Session object relative to this request

Type

\Cake\Http\Session

$stream protected

Request body stream. Contains php://input unless input constructor option is used.

Type

\Psr\Http\Message\StreamInterface

$trustProxy public

Whether or not to trust HTTP_X headers set by most load balancers.

Only set to true if your application runs behind load balancers/proxies that you control.

Type

bool

$trustedProxies protected

Trusted proxies list

Type

string[]

$uploadedFiles protected

Array of Psr\Http\Message\UploadedFileInterface objects.

Type

array

$uri protected

Uri instance

Type

\Psr\Http\Message\UriInterface

$webroot protected

webroot path segment for the request.

Type

string

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Http.ServerRequest.html