Index Documentation

HttpResponseBuilder extends HttpMessageBuilder
in package

Represents a HTTP response message builder.

Table of Contents

Methods

__construct()  : mixed
accelRedirect()  : void
Specifies an NGINX X-Accel-Redirect header.
addCookie()  : void
Adds a cookie to this response.
addHeader()  : void
Adds a header to the HTTP message.
addVary()  : void
Sets a Vary header.
clearSiteData()  : void
Specifies a Clear-Site-Data header.
clearStatusText()  : void
Clears the status text for this message.
getHeadersBuilder()  : HttpHeadersBuilder
Retrieves instance of the underlying HTTP header builder.
getStatusCode()  : int
Retrieves the HTTP status code for the target HTTP response message.
getStatusText()  : string
Retrieves the status text for this response.
hasContent()  : bool
Checks whether this HTTP message has body contents.
hasContentType()  : bool
Whether a Content-Type header is present.
hasHeader()  : bool
Checks if a header is already present.
hasStatusCode()  : bool
Checks whether this response message builder has a status code.
redirect()  : void
Specifies a redirect header on the response message.
removeCookie()  : void
Make the client remove a cookie.
removeHeader()  : void
Removes a header from the HTTP message.
sendFile()  : void
Specifies an Apache Web Server X-Sendfile header.
setCacheControl()  : void
Specifies a Cache-Control header.
setContent()  : void
Sets HTTP message body contents.
setContentType()  : void
Sets a Content-Type header.
setEntityTag()  : void
Sets an ETag header.
setFileName()  : void
Specifies a Content-Disposition header to supply a filename for the content.
setHeader()  : void
Sets a header to the HTTP message.
setHttpVersion()  : void
Sets HTTP version for the message.
setPoweredBy()  : void
Sets an X-Powered-By header.
setServerTiming()  : void
Sets a Server-Timing header.
setStatusCode()  : void
Sets the HTTP status code for the target HTTP response message.
setStatusText()  : void
Sets the status text for this response.
setTypeCss()  : void
Sets the Content-Type to 'text/css' with a provided character set for CSS content.
setTypeHtml()  : void
Sets the Content-Type to 'text/html' with a provided character set for HTML content.
setTypeJs()  : void
Sets the Content-Type to 'application/javascript' with a provided character set for Javascript content.
setTypeJson()  : void
Sets the Content-Type to 'application/json' with a provided character set for JSON content.
setTypePlain()  : void
Sets the Content-Type to 'text/plain' with a provided character set for plain text content.
setTypeStream()  : void
Sets the Content-Type to 'application/octet-stream' for raw content.
setTypeXml()  : void
Sets the Content-Type to 'application/xml' with a provided character set for XML content.
toResponse()  : HttpResponse
Creates an instance of HttpResponse from this builder.

Methods

accelRedirect()

Specifies an NGINX X-Accel-Redirect header.

public accelRedirect(string $uri) : void
Parameters
$uri : string

Relative URI to the content to serve.

addCookie()

Adds a cookie to this response.

public addCookie(string $name, string $value[, DateTimeInterface|int|null $expires = null ][, string $path = '' ][, string $domain = '' ][, bool $secure = false ][, bool $httpOnly = false ][, bool $sameSiteStrict = false ]) : void
Parameters
$name : string

Name of the cookie.

$value : string

Value of the cookie.

$expires : DateTimeInterface|int|null = null

Point at which the cookie should expire.

$path : string = ''

Path to which to apply the cookie.

$domain : string = ''

Domain name to which to apply the cookie.

$secure : bool = false

true to only make the client include this cookie in a secure context.

$httpOnly : bool = false

true to make the client hide this cookie to Javascript code.

$sameSiteStrict : bool = false

true to set the SameSite attribute to Strict, false to set it to Lax.

addHeader()

Adds a header to the HTTP message.

public addHeader(string $name, string $value) : void

If a header with the same name is already present, it will be appended with a new line.

Parameters
$name : string

Name of the header to add.

$value : string

Value to apply for this header.

addVary()

Sets a Vary header.

public addVary(string|array<string|int, string> $headers) : void
Parameters
$headers : string|array<string|int, string>

Header or headers that will vary.

clearSiteData()

Specifies a Clear-Site-Data header.

public clearSiteData(string ...$directives) : void
Parameters
$directives : string

Directives to specify.

clearStatusText()

Clears the status text for this message.

public clearStatusText() : void

getStatusCode()

Retrieves the HTTP status code for the target HTTP response message.

public getStatusCode() : int
Return values
int

HTTP status code.

getStatusText()

Retrieves the status text for this response.

public getStatusText() : string
Return values
string

Status text.

hasContent()

Checks whether this HTTP message has body contents.

public hasContent() : bool
Tags
phpstan-impure
Return values
bool

true if it has body contents.

hasContentType()

Whether a Content-Type header is present.

public hasContentType() : bool
Return values
bool

true if a Content-Type header is present.

hasHeader()

Checks if a header is already present.

public hasHeader(string $name) : bool
Parameters
$name : string

Name of the header.

Return values
bool

true if it is present.

hasStatusCode()

Checks whether this response message builder has a status code.

public hasStatusCode() : bool
Return values
bool

true if it has a status code greater than and including 100.

redirect()

Specifies a redirect header on the response message.

public redirect(string $to[, bool $permanent = false ]) : void
Parameters
$to : string

Target to redirect to.

$permanent : bool = false

true for status code 301, false for status code 302. Makes the client cache the redirect.

removeCookie()

Make the client remove a cookie.

public removeCookie(string $name[, string $path = '' ][, string $domain = '' ][, bool $secure = false ][, bool $httpOnly = false ][, bool $sameSiteStrict = false ]) : void
Parameters
$name : string

Name of the cookie.

$path : string = ''

Path to which the cookie was applied to cookie.

$domain : string = ''

Domain name to which the cookie was applied to cookie.

$secure : bool = false

true to only make the client include this cookie in a secure context.

$httpOnly : bool = false

true to make the client hide this cookie to Javascript code.

$sameSiteStrict : bool = false

true to set the SameSite attribute to Strict, false to set it to Lax.

removeHeader()

Removes a header from the HTTP message.

public removeHeader(string $name) : void
Parameters
$name : string

Name of the header to remove.

sendFile()

Specifies an Apache Web Server X-Sendfile header.

public sendFile(string $absolutePath) : void
Parameters
$absolutePath : string

Absolute path to the content to serve.

setCacheControl()

Specifies a Cache-Control header.

public setCacheControl(string ...$directives) : void
Parameters
$directives : string

Directives to specify.

setContent()

Sets HTTP message body contents.

public setContent(HttpContent|Stringable|string|int|float|resource|null $content) : void
Parameters
$content : HttpContent|Stringable|string|int|float|resource|null

Body contents

setContentType()

Sets a Content-Type header.

public setContentType(MediaType|string $mediaType) : void
Parameters
$mediaType : MediaType|string

Media type to set as the content type of the response body.

setEntityTag()

Sets an ETag header.

public setEntityTag(string $eTag[, bool $weak = false ]) : void
Parameters
$eTag : string

Unique identifier for the current state of the content.

$weak : bool = false

Whether to use weak matching.

setFileName()

Specifies a Content-Disposition header to supply a filename for the content.

public setFileName(string $fileName[, bool $attachment = false ]) : void
Parameters
$fileName : string

Name of the file.

$attachment : bool = false

true if the browser should prompt the user to download the body.

setHeader()

Sets a header to the HTTP message.

public setHeader(string $name, string $value) : void

If a header with the same name is already present, it will be overwritten.

Parameters
$name : string

Name of the header to set.

$value : string

Value to apply for this header.

setHttpVersion()

Sets HTTP version for the message.

public setHttpVersion(string $version) : void
Parameters
$version : string

HTTP version.

setPoweredBy()

Sets an X-Powered-By header.

public setPoweredBy(string $poweredBy) : void
Parameters
$poweredBy : string

Thing that your website is powered by.

setServerTiming()

Sets a Server-Timing header.

public setServerTiming(Timings $timings) : void
Parameters
$timings : Timings

Timings to supply to the devtools.

setStatusCode()

Sets the HTTP status code for the target HTTP response message.

public setStatusCode(int $statusCode) : void
Parameters
$statusCode : int

HTTP status code.

setStatusText()

Sets the status text for this response.

public setStatusText(string $statusText) : void
Parameters
$statusText : string

Status text.

setTypeCss()

Sets the Content-Type to 'text/css' with a provided character set for CSS content.

public setTypeCss([string $charset = 'utf-8' ]) : void
Parameters
$charset : string = 'utf-8'

Character set.

setTypeHtml()

Sets the Content-Type to 'text/html' with a provided character set for HTML content.

public setTypeHtml([string $charset = 'utf-8' ]) : void
Parameters
$charset : string = 'utf-8'

Character set.

setTypeJs()

Sets the Content-Type to 'application/javascript' with a provided character set for Javascript content.

public setTypeJs([string $charset = 'utf-8' ]) : void
Parameters
$charset : string = 'utf-8'

Character set.

setTypeJson()

Sets the Content-Type to 'application/json' with a provided character set for JSON content.

public setTypeJson([string $charset = 'utf-8' ]) : void
Parameters
$charset : string = 'utf-8'

Character set.

setTypePlain()

Sets the Content-Type to 'text/plain' with a provided character set for plain text content.

public setTypePlain([string $charset = 'us-ascii' ]) : void
Parameters
$charset : string = 'us-ascii'

Character set.

setTypeStream()

Sets the Content-Type to 'application/octet-stream' for raw content.

public setTypeStream() : void

setTypeXml()

Sets the Content-Type to 'application/xml' with a provided character set for XML content.

public setTypeXml([string $charset = 'utf-8' ]) : void
Parameters
$charset : string = 'utf-8'

Character set.


        
On this page

Search results