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

Trait MessageTrait

Implements the methods defined in Psr\Http\Message\MessageInterface.

Namespace: Cake\Http

Property Summary

  • $headerNames protected
    array<non-empty-string, non-empty-string>

    Map of lowercased header name to the original name used to register the header.

  • $headers protected
    array<non-empty-string, non-empty-list<string>>

    List of all registered headers, as original name => list of values.

  • $protocol protected
    string

    The HTTP protocol version.

  • $stream protected
    Psr\Http\Message\StreamInterface

    The message body.

Method Summary

  • assertHeaderName() protected

    Validate a header name.

  • assertStatus() protected

    Validate status line components before they reach an emitter.

  • filterHeaderValue() protected

    Validate and normalize header values.

  • getBody() public

    Gets the body of the message.

  • getHeader() public

    Retrieves a message header value by the given case-insensitive name.

  • getHeaderLine() public

    Retrieves a comma-separated string of the values for a single header.

  • getHeaders() public

    Retrieves all message headers.

  • getProtocolVersion() public

    Retrieves the HTTP protocol version as a string.

  • hasHeader() public

    Checks if a header exists by the given case-insensitive name.

  • removeHeader() protected

    Remove a header from the current instance.

  • replaceHeader() protected

    Replace a header on the current instance.

  • withAddedHeader() public

    Return an instance with the specified header appended with the given value.

  • withBody() public

    Return an instance with the specified message body.

  • withHeader() public

    Return an instance with the provided header, replacing any existing values of any headers with the same case-insensitive name.

  • withProtocolVersion() public

    Return an instance with the specified HTTP protocol version.

  • withoutHeader() public

    Return an instance without the specified header.

Method Detail

assertHeaderName() ¶ protected

assertHeaderName(string $name): void

Validate a header name.

Parameters
string $name

The header name.

Returns
void
Throws
InvalidArgumentException
When the name isn't a valid RFC 7230 token.

assertStatus() ¶ protected

assertStatus(int $code, string $reasonPhrase): void

Validate status line components before they reach an emitter.

Parameters
int $code

HTTP status code.

string $reasonPhrase

Optional reason phrase.

Returns
void

filterHeaderValue() ¶ protected

filterHeaderValue(mixed $values): non-empty-list<string>

Validate and normalize header values.

Parameters
mixed $values

A header value or list of header values.

Returns
non-empty-list<string>
Throws
InvalidArgumentException
When a value is invalid.

getBody() ¶ public

getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Returns
Psr\Http\Message\StreamInterface

getHeader() ¶ public

getHeader(string $name): list<string>

Retrieves a message header value by the given case-insensitive name.

Parameters
string $name

Case-insensitive header name.

Returns
list<string>

The header values, or an empty array if the header is not set.

getHeaderLine() ¶ public

getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Parameters
string $name

Case-insensitive header name.

Returns
string

The header values joined by a comma, or an empty string if the header is not set.

getHeaders() ¶ public

getHeaders(): array<non-empty-string, non-empty-list<string>>

Retrieves all message headers.

Returns
array<non-empty-string, non-empty-list<string>>

Header names mapped to their list of values.

getProtocolVersion() ¶ public

getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Returns
string

HTTP protocol version.

hasHeader() ¶ public

hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
string $name

Case-insensitive header name.

Returns
bool

removeHeader() ¶ protected

removeHeader(string $name): void

Remove a header from the current instance.

Parameters
string $name

Case-insensitive header name.

Returns
void

replaceHeader() ¶ protected

replaceHeader(non-empty-string $name, non-empty-list<string> $value): void

Replace a header on the current instance.

Parameters
non-empty-string $name

The header name.

non-empty-list<string> $value

The filtered header values.

Returns
void

withAddedHeader() ¶ public

withAddedHeader(string $name, array<string>|string $value): static

Return an instance with the specified header appended with the given value.

Parameters
string $name

Case-insensitive header name.

array<string>|string $value

Header value(s).

Returns
static
Throws
InvalidArgumentException
For invalid header names or values.

withBody() ¶ public

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

Return an instance with the specified message body.

Parameters
Psr\Http\Message\StreamInterface $body

The new body.

Returns
static

withHeader() ¶ public

withHeader(string $name, array<string>|string $value): static

Return an instance with the provided header, replacing any existing values of any headers with the same case-insensitive name.

Parameters
string $name

Case-insensitive header name.

array<string>|string $value

Header value(s).

Returns
static
Throws
InvalidArgumentException
For invalid header names or values.

withProtocolVersion() ¶ public

withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Parameters
string $version

HTTP protocol version.

Returns
static
Throws
InvalidArgumentException
For unsupported protocol versions.

withoutHeader() ¶ public

withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
string $name

Case-insensitive header name.

Returns
static

Property Detail

$headerNames ¶ protected

Map of lowercased header name to the original name used to register the header.

Type
array<non-empty-string, non-empty-string>

$headers ¶ protected

List of all registered headers, as original name => list of values.

Type
array<non-empty-string, non-empty-list<string>>

$protocol ¶ protected

The HTTP protocol version.

Type
string

$stream ¶ protected

The message body.

Type
Psr\Http\Message\StreamInterface
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