Response

The request library is already loaded in provider (also called container).

You can access the request in your controller methods either through the second parameter or by injecting the RequestInterface into the constructor via dependency injection.

class Pages extends BaseController
{

    public function about(ResponseInterface $response, RequestInterface $request): ResponseInterface
    {
        // Access parsed body (_POST)
        $postParams = $request->getParsedBody();
        
        return $response;
    }
}

Method list

Query Parameters

The getQueryParams method retrieves deserialized query string arguments from the incoming request. These query parameters are typically part of the request's URI ($_GET) and can be used to convey additional information to the server.

public function getQueryParams(): array

withQueryParams: Returns an instance with specified query string arguments.

Parsed Body

The Parsed Body deals with retrieving and manipulating the content of the request body, which can contain data sent by the client, such as form submissions or JSON payloads. The associated method bellow retrieves deserialized body parameters from the request. If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-datathen this method returns the contents of $_POST, while Content-Type is application/json or application/xml then JSON or XML payload is expected.

public function getParsedBody(): null|array|object

withParsedBody: Returns an instance with specified body parameters.

Server Parameters

Retrieves server parameters from the incoming request environment.

public function getServerParams(): array

Cookies

Retrieves cookies sent by the client to the server.

public function getCookieParams(): array

withCookieParams: Returns an instance with specified cookies.

Uploaded Files

Retrieves normalized file upload data.

public function getUploadedFiles(): array

withUploadedFiles: Returns an instance with specified uploaded files.

Attributes

Retrieves attributes derived from the request or Retrieves a single derived request attribute.

public function getAttributes(): array
public function getAttribute($name, $default = null): mixed

withAttribute: Returns an instance with specified derived request attribute. withoutAttribute: Returns an instance that removes the specified derived request attribute.

Request class

Request Target

Get the message request target (path+query)

public function getRequestTarget(): string

withRequestTarget: Return an instance with the specific set requestTarget

Request Method

Get the message request method (always as upper case)

public function getMethod(): string

withMethod: Return an instance with the specific set Method

Request URI

Get URI instance with set request message

public function getUri(): string

withUri: Return an instance with the with a new instance of UriInterface set

Is SSL?

Check if is request is SSL

public function isSSL(): bool

Server request port

Get Server request port

public function getPort(): int

Methods for Immutability

The following methods ensure immutability:

  • withCookieParams

  • withQueryParams

  • withUploadedFiles

  • withParsedBody

  • withAttribute

  • withoutAttribute

  • withRequestTarget

  • withMethod

  • withUri

These methods create and return a new instance with the updated values, preserving the immutability of the original ServerRequest object.

Last updated