Request
extends AbstractMessage
in package
implements
RequestInterface
HTTP request class to send requests
Interfaces, Classes and Traits
- RequestInterface
- Generic HTTP request interface
Table of Contents
- $client : ClientInterface
- $curlOptions : Collection
- $eventDispatcher : EventDispatcherInterface
- $headerFactory : HeaderFactoryInterface
- $headers : array<string|int, mixed>
- $isRedirect : bool
- $method : string
- $params : Collection
- $password : string
- $protocol : string
- $protocolVersion : string
- $response : Response
- $responseBody : EntityBodyInterface
- $state : string
- $url : Url
- $username : string
- __clone() : mixed
- __construct() : mixed
- __toString() : string
- Get the HTTP request as a string
- addCacheControlDirective() : mixed
- addCookie() : self
- Add a Cookie value by name to the Cookie header
- addHeader() : self
- Add a header to an existing collection of headers.
- addHeaders() : self
- Add and merge in an array of HTTP headers.
- addSubscriber() : mixed
- canCache() : mixed
- dispatch() : mixed
- getAllEvents() : mixed
- getCacheControlDirective() : mixed
- getClient() : ClientInterface
- Get the client used to transport the request
- getCookie() : null|string
- Get a cookie value by name
- getCookies() : array<string|int, mixed>
- Get an array of Cookies
- getCurlOptions() : Collection
- Get the cURL options that will be applied when the cURL handle is created
- getEventDispatcher() : mixed
- getHeader() : Header|null
- Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.
- getHeaderLines() : array<string|int, mixed>
- Get an array of message header lines (e.g. ["Host: example.com", ...])
- getHeaders() : HeaderCollection
- Get all headers as a collection
- getHost() : string
- Get the host of the request
- getMethod() : string
- Get the HTTP method of the request
- getParams() : Collection
- Get application and plugin specific parameters set on the message.
- getPassword() : string|null
- Get the password to pass in the URL if set
- getPath() : string
- Get the path of the request (e.g. '/', '/index.html')
- getPort() : int|null
- Get the port that the request will be sent on if it has been set
- getProtocolVersion() : string
- Get the HTTP protocol version of the request
- getQuery() : QueryString
- Get the collection of key value pairs that will be used as the query string in the request
- getRawHeaders() : mixed
- getResource() : string
- Get the resource part of the the request, including the path, query string, and fragment
- getResponse() : Response|null
- Get the previously received {@see Response} or NULL if the request has not been sent
- getResponseBody() : EntityBodyInterface
- Get the EntityBody that will hold the resulting response message's entity body. This response body will only be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response body.
- getScheme() : string
- Get the URI scheme of the request (http, https, ftp, etc)
- getState() : string
- Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
- getTokenizedHeader() : mixed
- getUrl() : string|Url
- Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
- getUsername() : string|null
- Get the username to pass in the URL if set
- hasCacheControlDirective() : mixed
- hasHeader() : bool
- Check if the specified header is present.
- isRedirect() : mixed
- isResponseBodyRepeatable() : bool
- Determine if the response body is repeatable (readable + seekable)
- onRequestError() : mixed
- Default method that will throw exceptions if an unsuccessful response is received.
- removeCacheControlDirective() : mixed
- removeCookie() : self
- Remove a specific cookie value by name
- removeHeader() : self
- Remove a specific HTTP header.
- send() : Response
- Send the request
- setAuth() : self
- Set HTTP authorization parameters
- setClient() : self
- Set the client used to transport the request
- setEventDispatcher() : mixed
- setHeader() : self
- Set an HTTP header and overwrite any existing value for the header
- setHeaderFactory() : self
- Set the header factory to use to create headers
- setHeaders() : self
- Overwrite all HTTP headers with the supplied array of headers
- setHost() : self
- Set the host of the request. Including a port in the host will modify the port of the request.
- setIsRedirect() : mixed
- setPath() : self
- Set the path of the request (e.g. '/', '/index.html')
- setPort() : self
- Set the port that the request will be sent on
- setProtocolVersion() : self
- Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
- setResponse() : self
- Manually set a response for the request.
- setResponseBody() : Request
- Set the EntityBody that will hold a successful response message's entity body.
- setScheme() : self
- Set the URI scheme of the request (http, https, ftp, etc)
- setState() : string
- Set the state of the request
- setTokenizedHeader() : mixed
- setUrl() : self
- Set the URL of the request
- startResponse() : self
- The start of a response has been received for a request and the request is still in progress
- getEventArray() : array<string|int, mixed>
- Get an array containing the request and response for event notifications
- processResponse() : mixed
- Process a received response
Properties
$client
protected
ClientInterface
$client
$curlOptions
protected
Collection
$curlOptions
cURL specific transfer options
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$headerFactory
protected
HeaderFactoryInterface
$headerFactory
$headers
protected
array<string|int, mixed>
$headers
HTTP header collection
$isRedirect
protected
bool
$isRedirect
= false
$method
protected
string
$method
HTTP method (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE)
$params
protected
Collection
$params
Custom message parameters that are extendable by plugins
$password
protected
string
$password
Auth password
$protocol
protected
string
$protocol
= 'HTTP'
Message protocol
$protocolVersion
protected
string
$protocolVersion
= '1.1'
HTTP protocol version of the message
$response
protected
Response
$response
Response of the request
$responseBody
protected
EntityBodyInterface
$responseBody
Response body
$state
protected
string
$state
State of the request object
$url
protected
Url
$url
HTTP Url
$username
protected
string
$username
Authentication username
Methods
__clone()
public
__clone() : mixed
Return values
mixed —__construct()
public
__construct(string $method, string|Url $url[, array<string|int, mixed>|Collection $headers = array() ]) : mixed
Parameters
- $method : string
-
HTTP method
- $url : string|Url
-
HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the full URL. If query string parameters are present they will be parsed as well.
- $headers : array<string|int, mixed>|Collection = array()
-
HTTP headers
Return values
mixed —__toString()
Get the HTTP request as a string
public
__toString() : string
Return values
string —addCacheControlDirective()
public
addCacheControlDirective(mixed $directive[, mixed $value = true ]) : mixed
Parameters
- $directive : mixed
- $value : mixed = true
Tags
Return values
mixed —addCookie()
Add a Cookie value by name to the Cookie header
public
addCookie(mixed $name, mixed $value) : self
Parameters
- $name : mixed
-
Name of the cookie to add
- $value : mixed
-
Value to set
Return values
self —addHeader()
Add a header to an existing collection of headers.
public
addHeader(mixed $header, mixed $value) : self
Parameters
- $header : mixed
-
Header name to add
- $value : mixed
-
Value of the header
Return values
self —addHeaders()
Add and merge in an array of HTTP headers.
public
addHeaders(array<string|int, mixed> $headers) : self
Parameters
- $headers : array<string|int, mixed>
-
Associative array of header data.
Return values
self —addSubscriber()
public
addSubscriber(EventSubscriberInterface $subscriber) : mixed
Parameters
- $subscriber : EventSubscriberInterface
Return values
mixed —canCache()
public
canCache() : mixed
Tags
Return values
mixed —dispatch()
public
dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : mixed
Parameters
- $eventName : mixed
- $context : array<string|int, mixed> = array()
Return values
mixed —getAllEvents()
public
static getAllEvents() : mixed
Return values
mixed —getCacheControlDirective()
public
getCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
Return values
mixed —getClient()
Get the client used to transport the request
public
getClient() : ClientInterface
Return values
ClientInterface —$client
getCookie()
Get a cookie value by name
public
getCookie(mixed $name) : null|string
Parameters
- $name : mixed
-
Cookie to retrieve
Return values
null|string —getCookies()
Get an array of Cookies
public
getCookies() : array<string|int, mixed>
Return values
array<string|int, mixed> —getCurlOptions()
Get the cURL options that will be applied when the cURL handle is created
public
getCurlOptions() : Collection
Return values
Collection —getEventDispatcher()
public
getEventDispatcher() : mixed
Return values
mixed —getHeader()
Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.
public
getHeader(mixed $header) : Header|null
Parameters
- $header : mixed
-
Header to retrieve.
Return values
Header|null —getHeaderLines()
Get an array of message header lines (e.g. ["Host: example.com", ...])
public
getHeaderLines() : array<string|int, mixed>
Return values
array<string|int, mixed> —getHeaders()
Get all headers as a collection
public
getHeaders() : HeaderCollection
Return values
HeaderCollection —getHost()
Get the host of the request
public
getHost() : string
Return values
string —getMethod()
Get the HTTP method of the request
public
getMethod() : string
Return values
string —getParams()
Get application and plugin specific parameters set on the message.
public
getParams() : Collection
Return values
Collection —getPassword()
Get the password to pass in the URL if set
public
getPassword() : string|null
Return values
string|null —getPath()
Get the path of the request (e.g. '/', '/index.html')
public
getPath() : string
Return values
string —getPort()
Get the port that the request will be sent on if it has been set
public
getPort() : int|null
Return values
int|null —getProtocolVersion()
Get the HTTP protocol version of the request
public
getProtocolVersion() : string
Return values
string —getQuery()
Get the collection of key value pairs that will be used as the query string in the request
public
getQuery([mixed $asString = false ]) : QueryString
Parameters
- $asString : mixed = false
Return values
QueryString —getRawHeaders()
public
getRawHeaders() : mixed
Return values
mixed —getResource()
Get the resource part of the the request, including the path, query string, and fragment
public
getResource() : string
Return values
string —getResponse()
Get the previously received {@see Response} or NULL if the request has not been sent
public
getResponse() : Response|null
Return values
Response|null —getResponseBody()
Get the EntityBody that will hold the resulting response message's entity body. This response body will only be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response body.
public
getResponseBody() : EntityBodyInterface
Return values
EntityBodyInterface —getScheme()
Get the URI scheme of the request (http, https, ftp, etc)
public
getScheme() : string
Return values
string —getState()
Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
public
getState() : string
Return values
string —getTokenizedHeader()
public
getTokenizedHeader(mixed $header[, mixed $token = ';' ]) : mixed
Parameters
- $header : mixed
- $token : mixed = ';'
Tags
Return values
mixed —getUrl()
Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
public
getUrl([mixed $asObject = false ]) : string|Url
Parameters
- $asObject : mixed = false
-
Set to TRUE to retrieve the URL as a clone of the URL object owned by the request.
Return values
string|Url —getUsername()
Get the username to pass in the URL if set
public
getUsername() : string|null
Return values
string|null —hasCacheControlDirective()
public
hasCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
Return values
mixed —hasHeader()
Check if the specified header is present.
public
hasHeader(mixed $header) : bool
Parameters
- $header : mixed
-
The header to check.
Return values
bool —isRedirect()
public
isRedirect() : mixed
Tags
Return values
mixed —isResponseBodyRepeatable()
Determine if the response body is repeatable (readable + seekable)
public
isResponseBodyRepeatable() : bool
Tags
Return values
bool —onRequestError()
Default method that will throw exceptions if an unsuccessful response is received.
public
static onRequestError(Event $event) : mixed
Parameters
- $event : Event
-
Received
Tags
Return values
mixed —removeCacheControlDirective()
public
removeCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
Return values
mixed —removeCookie()
Remove a specific cookie value by name
public
removeCookie(mixed $name) : self
Parameters
- $name : mixed
-
Cookie to remove by name
Return values
self —removeHeader()
Remove a specific HTTP header.
public
removeHeader(mixed $header) : self
Parameters
- $header : mixed
-
HTTP header to remove.
Return values
self —send()
Send the request
public
send() : Response
Return values
Response —setAuth()
Set HTTP authorization parameters
public
setAuth(mixed $user[, mixed $password = '' ][, mixed $scheme = CURLAUTH_BASIC ]) : self
Parameters
- $user : mixed
-
User name or false disable authentication
- $password : mixed = ''
-
Password
- $scheme : mixed = CURLAUTH_BASIC
-
Authentication scheme ('Basic', 'Digest', or a CURLAUTH_* constant (deprecated))
Return values
self —setClient()
Set the client used to transport the request
public
setClient(ClientInterface $client) : self
Parameters
- $client : ClientInterface
Return values
self —setEventDispatcher()
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : mixed
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
mixed —setHeader()
Set an HTTP header and overwrite any existing value for the header
public
setHeader(mixed $header, mixed $value) : self
Parameters
- $header : mixed
-
Name of the header to set.
- $value : mixed
-
Value to set.
Return values
self —setHeaderFactory()
Set the header factory to use to create headers
public
setHeaderFactory(HeaderFactoryInterface $factory) : self
Parameters
- $factory : HeaderFactoryInterface
Return values
self —setHeaders()
Overwrite all HTTP headers with the supplied array of headers
public
setHeaders(array<string|int, mixed> $headers) : self
Parameters
- $headers : array<string|int, mixed>
-
Associative array of header data.
Return values
self —setHost()
Set the host of the request. Including a port in the host will modify the port of the request.
public
setHost(mixed $host) : self
Parameters
- $host : mixed
-
Host to set (e.g. www.yahoo.com, www.yahoo.com:80)
Return values
self —setIsRedirect()
public
setIsRedirect(mixed $isRedirect) : mixed
Parameters
- $isRedirect : mixed
Tags
Return values
mixed —setPath()
Set the path of the request (e.g. '/', '/index.html')
public
setPath(mixed $path) : self
Parameters
- $path : mixed
-
Path to set or array of segments to implode
Return values
self —setPort()
Set the port that the request will be sent on
public
setPort(mixed $port) : self
Parameters
- $port : mixed
-
Port number to set
Return values
self —setProtocolVersion()
Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
public
setProtocolVersion(mixed $protocol) : self
Parameters
- $protocol : mixed
-
HTTP protocol version to use with the request
Return values
self —setResponse()
Manually set a response for the request.
public
setResponse(Response $response[, mixed $queued = false ]) : self
This method is useful for specifying a mock response for the request or setting the response using a cache. Manually setting a response will bypass the actual sending of a request.
Parameters
- $response : Response
-
Response object to set
- $queued : mixed = false
-
Set to TRUE to keep the request in a state of not having been sent, but queue the response for send()
Return values
self —Returns a reference to the object.
setResponseBody()
Set the EntityBody that will hold a successful response message's entity body.
public
setResponseBody(mixed $body) : Request
This method should be invoked when you need to send the response's entity body somewhere other than the normal php://temp buffer. For example, you can send the entity body to a socket, file, or some other custom stream.
Parameters
- $body : mixed
-
Response body object. Pass a string to attempt to store the response body in a local file.
Return values
Request —setScheme()
Set the URI scheme of the request (http, https, ftp, etc)
public
setScheme(mixed $scheme) : self
Parameters
- $scheme : mixed
-
Scheme to set
Return values
self —setState()
Set the state of the request
public
setState(mixed $state[, array<string|int, mixed> $context = array() ]) : string
Parameters
- $state : mixed
-
State of the request ('complete', 'transfer', 'new', 'error')
- $context : array<string|int, mixed> = array()
-
Contextual information about the state change
Return values
string —Returns the current state of the request (which may have changed due to events being fired)
setTokenizedHeader()
public
setTokenizedHeader(mixed $header, mixed $data[, mixed $token = ';' ]) : mixed
Parameters
- $header : mixed
- $data : mixed
- $token : mixed = ';'
Tags
Return values
mixed —setUrl()
Set the URL of the request
public
setUrl(mixed $url) : self
Parameters
- $url : mixed
Return values
self —startResponse()
The start of a response has been received for a request and the request is still in progress
public
startResponse(Response $response) : self
Parameters
- $response : Response
-
Response that has been received so far
Return values
self —getEventArray()
Get an array containing the request and response for event notifications
protected
getEventArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —processResponse()
Process a received response
protected
processResponse([array<string|int, mixed> $context = array() ]) : mixed
Parameters
- $context : array<string|int, mixed> = array()
-
Contextual information