Message class abstract

Framework\HTTP\Message

Class Message.

Implements: Framework\HTTP\MessageInterface, Stringable

Defined in libraries/http/src/Message.php

Properties #

$protocol
HTTP Message Protocol.
$url
HTTP Request URL.
$method
HTTP Request Method.
$statusCode
HTTP Response Status Code.
$body
HTTP Message Body.
$cookies
HTTP Message Cookies.
$headers
HTTP Message Headers.
$jsonFlags
-

$protocol

protected string $protocol = 'HTTP/1.1'

HTTP Message Protocol.

$url

protected \Framework\HTTP\URL $url

HTTP Request URL.

$method

protected string $method

HTTP Request Method.

$statusCode

protected int $statusCode

HTTP Response Status Code.

$body

protected string $body

HTTP Message Body.

$cookies

protected array $cookies = array ( )

HTTP Message Cookies.

$headers

protected array $headers = array ( )

HTTP Message Headers.

$jsonFlags

protected int $jsonFlags = 320

Methods #

__toString()
-
getBody()
Get the Message body.
getCookie()
Get a Cookie by name.
getCookies()
Get all Cookies.
getHeader()
-
getHeaderLine()
-
getHeaderLines()
-
getHeaders()
-
getJsonFlags()
Get JSON flags.
getProtocol()
Get the HTTP protocol.
getStartLine()
Get the Message Start-Line.
hasCookie()
Say if the Message has a Cookie.
hasHeader()
-
parseQualityValues()
-
setJsonFlags()
Set JSON flags.
appendHeader()
Append a Message header.
getMethod()
Gets the HTTP Request Method.
getStatusCode()
Get the status code.
getUrl()
Gets the requested URL.
isMethod()
-
isStatusCode()
-
parseContentType()
-
removeCookie()
Remove a Cookie by name.
removeCookies()
Remove many Cookies by names.
removeHeader()
Remove a header by name.
removeHeaders()
Remove all headers.
removeHeadersByNames()
Remove headers by names.
setBody()
Set the Message body.
setCookie()
Set a new Cookie.
setCookies()
Set a list of Cookies.
setHeader()
Set a Message header.
setHeaders()
Set a list of headers.
setMethod()
Set the request method.
setProtocol()
Set the HTTP protocol.
setStatusCode()
-
setUrl()
Set the Message URL.
getHeaderValueSeparator()
-

__toString()

public function __toString(): string
Returns string

getBody()

public function getBody(): string

Get the Message body.

Returns string

getCookie()

public function getCookie(string $name): ?\Framework\HTTP\Cookie

Get a Cookie by name.

Parameters
  • string $name
Returns ?\Framework\HTTP\Cookie

getCookies()

public function getCookies(): array

Get all Cookies.

Returns array

getHeader()

public function getHeader(string $name): ?string
Parameters
  • string $name
Returns ?string

getHeaderLine()

public function getHeaderLine(string $name): ?string
Parameters
  • string $name
Returns ?string

getHeaderLines()

public function getHeaderLines(): array
Returns array

getHeaders()

public function getHeaders(): array
Returns array

getJsonFlags()

public function getJsonFlags(): int

Get JSON flags.

Returns int

getProtocol()

public function getProtocol(): string

Get the HTTP protocol.

Returns string

getStartLine()

public function getStartLine(): string

Get the Message Start-Line.

Returns string
throws
BadMethodCallException if $this is not an instance of RequestInterface or ResponseInterface

hasCookie()

public function hasCookie(string $name): bool

Say if the Message has a Cookie.

Parameters
  • string $name - Cookie name
Returns bool

hasHeader()

public function hasHeader(string $name, ?string $value = NULL): bool
Parameters
  • string $name
  • ?string $value
Returns bool

parseQualityValues()

public static function parseQualityValues(?string $string): array
Parameters
  • ?string $string
Returns array

setJsonFlags()

public function setJsonFlags(int $flags): static

Set JSON flags.

Parameters
  • int $flags
Returns static

appendHeader()

protected function appendHeader(string $name, string $value): static

Append a Message header.

Used to set repeated header field names.

Parameters
  • string $name
  • string $value
Returns static

getMethod()

protected function getMethod(): string

Gets the HTTP Request Method.

Returns string - $method One of: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, or TRACE

getStatusCode()

protected function getStatusCode(): int

Get the status code.

Returns int

getUrl()

protected function getUrl(): \Framework\HTTP\URL

Gets the requested URL.

Returns \Framework\HTTP\URL

isMethod()

protected function isMethod(string $method): bool
Parameters
  • string $method
Returns bool
throws
InvalidArgumentException for invalid method

isStatusCode()

protected function isStatusCode(int $code): bool
Parameters
  • int $code
Returns bool

parseContentType()

protected function parseContentType(): ?string
Returns ?string

removeCookie()

protected function removeCookie(string $name): static

Remove a Cookie by name.

Parameters
  • string $name
Returns static

removeCookies()

protected function removeCookies(array $names): static

Remove many Cookies by names.

Parameters
  • array $names
Returns static

removeHeader()

protected function removeHeader(string $name): static

Remove a header by name.

Parameters
  • string $name
Returns static

removeHeaders()

protected function removeHeaders(): static

Remove all headers.

Returns static

removeHeadersByNames()

protected function removeHeadersByNames(array $names): static

Remove headers by names.

Parameters
  • array $names
Returns static

setBody()

protected function setBody(string $body): static

Set the Message body.

Parameters
  • string $body
Returns static

setCookie()

protected function setCookie(\Framework\HTTP\Cookie $cookie): static

Set a new Cookie.

Parameters
  • \Framework\HTTP\Cookie $cookie
Returns static

setCookies()

protected function setCookies(array $cookies): static

Set a list of Cookies.

Parameters
  • array $cookies
Returns static

setHeader()

protected function setHeader(string $name, string $value): static

Set a Message header.

Parameters
  • string $name
  • string $value
Returns static

setHeaders()

protected function setHeaders(array $headers): static

Set a list of headers.

Parameters
  • array $headers
Returns static

setMethod()

protected function setMethod(string $method): static

Set the request method.

Parameters
  • string $method - One of: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, or TRACE
Returns static
throws
InvalidArgumentException for invalid method

setProtocol()

protected function setProtocol(string $protocol): static

Set the HTTP protocol.

Parameters
  • string $protocol - HTTP/1.1, HTTP/2, etc
Returns static

setStatusCode()

protected function setStatusCode(int $code): static
Parameters
  • int $code
Returns static

setUrl()

protected function setUrl(\Framework\HTTP\URL|string $url): static

Set the Message URL.

Parameters
  • \Framework\HTTP\URL|string $url
Returns static

getHeaderValueSeparator()

private function getHeaderValueSeparator(string $headerName): string
Parameters
  • string $headerName
Returns string