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 3.7 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.7
      • 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
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class ServerRequestFactory

Factory for making ServerRequest instances.

This subclass 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.

Abstract
Namespace: Cake\Http

Method Summary

  • createUri() public static

    Create a new Uri instance from the provided server data.

  • fromGlobals() public static

    Create a request from the supplied superglobal values.

  • get() public static deprecated

    Access a value in an array, returning a default value if not found

  • getBase() protected static

    Calculate the base directory and webroot directory.

  • getHeader() public static deprecated

    Search for a header value.

  • marshalHeaders() public static deprecated

    Marshal headers from $_SERVER

  • marshalHostAndPortFromHeaders() public static deprecated

    Marshal the host and port from HTTP headers and/or the PHP environment

  • marshalRequestUri() public static deprecated

    Detect the base URI for the request

  • marshalUriFromServer() public static

    Build a UriInterface object.

  • normalizeFiles() public static deprecated

    Normalize uploaded files

  • normalizeServer() public static

    Marshal the $_SERVER array

  • stripQueryString() public static deprecated

    Strip the query string from a path

  • updatePath() protected static

    Updates the request URI to remove the base directory.

Method Detail

createUri() ¶ public static

createUri(array $server = []): Psr\Http\Message\UriInterface

Create a new Uri instance from the provided server data.

Parameters
array $server optional

Array of server data to build the Uri from. $_SERVER will be added into the $server parameter.

Returns
Psr\Http\Message\UriInterface

fromGlobals() ¶ public static

fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null): ServerRequest

Create a request from the supplied superglobal values.

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

The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers.

Parameters
array $server optional
array $query optional
array $body optional
array $cookies optional
array $files optional
Returns
ServerRequest

get() ¶ public static

get(string $key, array $values, mixed $default = null): mixed

Access a value in an array, returning a default value if not found

Parameters
string $key
array $values
mixed $default optional
Returns
mixed

getBase() ¶ protected static

getBase(Psr\Http\Message\UriInterface $uri, array $server): array

Calculate the base directory and webroot directory.

Parameters
Psr\Http\Message\UriInterface $uri

The Uri instance.

array $server

The SERVER data to use.

Returns
array

getHeader() ¶ public static

getHeader(string $header, array $headers, mixed $default = null): string

Search for a header value.

Does a case-insensitive search for a matching header.

If found, it is returned as a string, using comma concatenation.

If not, the $default is returned.

Parameters
string $header
array $headers
mixed $default optional
Returns
string

marshalHeaders() ¶ public static

marshalHeaders(array $server): array

Marshal headers from $_SERVER

Parameters
array $server
Returns
array

marshalHostAndPortFromHeaders() ¶ public static

marshalHostAndPortFromHeaders(stdClass $accumulator, array $server, array $headers)

Marshal the host and port from HTTP headers and/or the PHP environment

Parameters
stdClass $accumulator
array $server
array $headers

marshalRequestUri() ¶ public static

marshalRequestUri(array $server): string

Detect the base URI for the request

Looks at a variety of criteria in order to attempt to autodetect a base URI, including rewrite URIs, proxy URIs, etc.

Parameters
array $server
Returns
string

marshalUriFromServer() ¶ public static

marshalUriFromServer(array $server, array $headers): Psr\Http\Message\UriInterface

Build a UriInterface object.

Add in some CakePHP specific logic/properties that help preserve backwards compatibility.

Parameters
array $server

The server parameters.

array $headers

The normalized headers

Returns
Psr\Http\Message\UriInterface

normalizeFiles() ¶ public static

normalizeFiles(array $files): array

Normalize uploaded files

Transforms each value into an UploadedFileInterface instance, and ensures that nested arrays are normalized.

Parameters
array $files
Returns
array
Throws
InvalidArgumentException
for unrecognized values

normalizeServer() ¶ public static

normalizeServer(array $server): array

Marshal the $_SERVER array

Pre-processes and returns the $_SERVER superglobal.

Parameters
array $server
Returns
array

stripQueryString() ¶ public static

stripQueryString(mixed $path): string

Strip the query string from a path

Parameters
mixed $path
Returns
string

updatePath() ¶ protected static

updatePath(string $base, Psr\Http\Message\UriInterface $uri): Psr\Http\Message\UriInterface

Updates the request URI to remove the base directory.

Parameters
string $base

The base path to remove.

Psr\Http\Message\UriInterface $uri

The uri to update.

Returns
Psr\Http\Message\UriInterface
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