CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Link
      • Middleware
      • RateLimit
      • Response
      • Session
      • TestSuite
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ServerRequestFactory

Factory for making ServerRequest instances.

This adds in CakePHP specific behavior to populate the basePath and webroot attributes. Furthermore the Uri's path is corrected to only contain the 'virtual' path for the request.

Namespace: Cake\Http

Method Summary

  • createServerRequest() public

    Create a new server request.

    Note that server-params are taken precisely as given - no parsing/processing of the given values is performed, and, in particular, no attempt is made to determine the HTTP method or URI, which must be provided explicitly.

  • createUploadedFiles() protected static

    Create uploaded file instances from a (possibly nested) $_FILES specification.

    PHP stores nested uploads as separate trees per attribute, e.g. ['tmp_name' => ['a' => ...], 'size' => ['a' => ...]].

  • fromGlobals() public static

    Create a request from the supplied superglobal values.

    If any argument is not supplied, the corresponding superglobal value will be used.

  • isFileAttributeTree() protected static

    Validate corresponding filename, size, and error leaves before transposing a tree.

  • isFileSpecification() protected static

    Recognize parallel PHP upload attributes by their leaf types, not form field names.

  • marshalBodyAndRequestMethod() protected static

    Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value. The 'ORIGINAL_REQUEST_METHOD' is also preserved, if you want the read the non-simulated HTTP method the client used.

    Override values are upper-cased and may only contain the letters A-Z, optionally separated by single hyphens or underscores (e.g. VERSION-CONTROL).

    Request body of content type "application/x-www-form-urlencoded" is parsed into array for PUT/PATCH/DELETE requests.

  • marshalFiles() protected static

    Process uploaded files and move things onto the parsed body.

  • normalizeOverrideMethod() protected static

    Normalize and validate a method override value.

    Only letters, optionally separated by single hyphens or underscores, are accepted to prevent arbitrary client supplied strings from ending up in REQUEST_METHOD, while still allowing custom methods like the WebDAV VERSION-CONTROL.

  • normalizeServer() protected static

    Populate HTTP_AUTHORIZATION from the Apache request headers.

    Some SAPI/httpd combinations don't expose the Authorization header in $_SERVER.

  • normalizeUploadedFiles() protected static

    Normalize a $_FILES structure into a tree of UploadedFileInterface instances.

Method Detail

createServerRequest() ¶ public

createServerRequest(string $method, UriInterface|string $uri, array $serverParams = []): Cake\Http\ServerRequest

Create a new server request.

Note that server-params are taken precisely as given - no parsing/processing of the given values is performed, and, in particular, no attempt is made to determine the HTTP method or URI, which must be provided explicitly.

Parameters
string $method

The HTTP method associated with the request.

UriInterface|string $uri

The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.

array $serverParams optional

Array of SAPI parameters with which to seed the generated request instance.

Returns
Cake\Http\ServerRequest

createUploadedFiles() ¶ protected static

createUploadedFiles(mixed $tmpName, mixed $size, mixed $error, mixed $name, mixed $type): Psr\Http\Message\UploadedFileInterface|array<array-key, \Psr\Http\Message\UploadedFileInterface|array<array-key, mixed>>

Create uploaded file instances from a (possibly nested) $_FILES specification.

PHP stores nested uploads as separate trees per attribute, e.g. ['tmp_name' => ['a' => ...], 'size' => ['a' => ...]].

Parameters
mixed $tmpName

The tmp_name value or tree.

mixed $size

The size value or tree.

mixed $error

The error value or tree.

mixed $name

The name value or tree.

mixed $type

The type value or tree.

Returns
Psr\Http\Message\UploadedFileInterface|array<array-key, \Psr\Http\Message\UploadedFileInterface|array<array-key, mixed>>
Throws
InvalidArgumentException
When the specification is incomplete.

fromGlobals() ¶ public static

fromGlobals(array|null $server = null, array|null $query = null, array|null $parsedBody = null, array|null $cookies = null, array|null $files = null): Cake\Http\ServerRequest

Create a request from the supplied superglobal values.

If any argument is not supplied, the corresponding superglobal value will be used.

Parameters
array|null $server optional

$_SERVER superglobal

array|null $query optional

$_GET superglobal

array|null $parsedBody optional

$_POST superglobal

array|null $cookies optional

$_COOKIE superglobal

array|null $files optional

$_FILES superglobal

Returns
Cake\Http\ServerRequest
Throws
InvalidArgumentException
for invalid file values

isFileAttributeTree() ¶ protected static

isFileAttributeTree(mixed $tmpName, mixed $size, mixed $error): bool

Validate corresponding filename, size, and error leaves before transposing a tree.

Parameters
mixed $tmpName

Filename or filename tree.

mixed $size

Size or size tree.

mixed $error

Error code or error tree.

Returns
bool

isFileSpecification() ¶ protected static

isFileSpecification(array $files): bool

Recognize parallel PHP upload attributes by their leaf types, not form field names.

Parameters
array $files

Candidate file specification or nested form group.

Returns
bool

marshalBodyAndRequestMethod() ¶ protected static

marshalBodyAndRequestMethod(array $parsedBody, Cake\Http\ServerRequest $request): Cake\Http\ServerRequest

Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value. The 'ORIGINAL_REQUEST_METHOD' is also preserved, if you want the read the non-simulated HTTP method the client used.

Override values are upper-cased and may only contain the letters A-Z, optionally separated by single hyphens or underscores (e.g. VERSION-CONTROL).

Request body of content type "application/x-www-form-urlencoded" is parsed into array for PUT/PATCH/DELETE requests.

Parameters
array $parsedBody

Parsed body.

Cake\Http\ServerRequest $request

Request instance.

Returns
Cake\Http\ServerRequest

marshalFiles() ¶ protected static

marshalFiles(array $files, Cake\Http\ServerRequest $request): Cake\Http\ServerRequest

Process uploaded files and move things onto the parsed body.

Parameters
array $files

Files array for normalization and merging in parsed body.

Cake\Http\ServerRequest $request

Request instance.

Returns
Cake\Http\ServerRequest

normalizeOverrideMethod() ¶ protected static

normalizeOverrideMethod(mixed $method): string

Normalize and validate a method override value.

Only letters, optionally separated by single hyphens or underscores, are accepted to prevent arbitrary client supplied strings from ending up in REQUEST_METHOD, while still allowing custom methods like the WebDAV VERSION-CONTROL.

Parameters
mixed $method

The method from the _method field or X-Http-Method-Override header.

Returns
string
Throws
Cake\Http\Exception\BadRequestException
When the method is not a valid override value.

normalizeServer() ¶ protected static

normalizeServer(array $server): array

Populate HTTP_AUTHORIZATION from the Apache request headers.

Some SAPI/httpd combinations don't expose the Authorization header in $_SERVER.

Parameters
array $server

The SERVER data to normalize.

Returns
array

normalizeUploadedFiles() ¶ protected static

normalizeUploadedFiles(array $files): array<array-key, \Psr\Http\Message\UploadedFileInterface|array<array-key, mixed>>

Normalize a $_FILES structure into a tree of UploadedFileInterface instances.

Parameters
array $files

The files data to normalize.

Returns
array<array-key, \Psr\Http\Message\UploadedFileInterface|array<array-key, mixed>>
Throws
InvalidArgumentException
For invalid file values.
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs