Request
extends AbstractMessage
in package
implements
RequestInterface
HTTP request class to send requests
Table of Contents
Interfaces
- RequestInterface
- Generic HTTP request interface
Properties
- $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
Methods
- __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() : self
- Add an event subscriber to the dispatcher
- canCache() : mixed
- dispatch() : Event
- Helper to dispatch Guzzle events and set the event name on the event
- getAllEvents() : array<string|int, mixed>
- Get a list of all of the events emitted from the class
- 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() : EventDispatcherInterface
- Get the EventDispatcher of the request
- 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() : string
- Get the raw message headers as a string
- 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() : self
- Set the EventDispatcher of the request
- 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
__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
__toString()
Get the HTTP request as a string
public
__toString() : string
Return values
stringaddCacheControlDirective()
public
addCacheControlDirective(mixed $directive[, mixed $value = true ]) : mixed
Parameters
- $directive : mixed
- $value : mixed = true
Tags
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
selfaddHeader()
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
selfaddHeaders()
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
selfaddSubscriber()
Add an event subscriber to the dispatcher
public
addSubscriber(EventSubscriberInterface $subscriber) : self
Parameters
- $subscriber : EventSubscriberInterface
-
Event subscriber
Return values
selfcanCache()
public
canCache() : mixed
Use Guzzle\Plugin\Cache\DefaultCanCacheStrategy
Tags
dispatch()
Helper to dispatch Guzzle events and set the event name on the event
public
dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
- $eventName : mixed
-
Name of the event to dispatch
- $context : array<string|int, mixed> = array()
-
Context of the event
Return values
Event —Returns the created event object
getAllEvents()
Get a list of all of the events emitted from the class
public
static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>getCacheControlDirective()
public
getCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
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|stringgetCookies()
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
CollectiongetEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfacegetHeader()
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|nullgetHeaderLines()
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
HeaderCollectiongetHost()
Get the host of the request
public
getHost() : string
Return values
stringgetMethod()
Get the HTTP method of the request
public
getMethod() : string
Return values
stringgetParams()
Get application and plugin specific parameters set on the message.
public
getParams() : Collection
Return values
CollectiongetPassword()
Get the password to pass in the URL if set
public
getPassword() : string|null
Return values
string|nullgetPath()
Get the path of the request (e.g. '/', '/index.html')
public
getPath() : string
Return values
stringgetPort()
Get the port that the request will be sent on if it has been set
public
getPort() : int|null
Return values
int|nullgetProtocolVersion()
Get the HTTP protocol version of the request
public
getProtocolVersion() : string
Return values
stringgetQuery()
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
QueryStringgetRawHeaders()
Get the raw message headers as a string
public
getRawHeaders() : string
Return values
stringgetResource()
Get the resource part of the the request, including the path, query string, and fragment
public
getResource() : string
Return values
stringgetResponse()
Get the previously received {@see Response} or NULL if the request has not been sent
public
getResponse() : Response|null
Return values
Response|nullgetResponseBody()
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
EntityBodyInterfacegetScheme()
Get the URI scheme of the request (http, https, ftp, etc)
public
getScheme() : string
Return values
stringgetState()
Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
public
getState() : string
Return values
stringgetTokenizedHeader()
public
getTokenizedHeader(mixed $header[, mixed $token = ';' ]) : mixed
Use $message->getHeader()->parseParams()
Parameters
- $header : mixed
- $token : mixed = ';'
Tags
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|UrlgetUsername()
Get the username to pass in the URL if set
public
getUsername() : string|null
Return values
string|nullhasCacheControlDirective()
public
hasCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
hasHeader()
Check if the specified header is present.
public
hasHeader(mixed $header) : bool
Parameters
- $header : mixed
-
The header to check.
Return values
boolisRedirect()
public
isRedirect() : mixed
Use the history plugin
Tags
isResponseBodyRepeatable()
Determine if the response body is repeatable (readable + seekable)
public
isResponseBodyRepeatable() : bool
Use getResponseBody()->isSeekable()
Tags
Return values
boolonRequestError()
Default method that will throw exceptions if an unsuccessful response is received.
public
static onRequestError(Event $event) : mixed
Parameters
- $event : Event
-
Received
Tags
removeCacheControlDirective()
public
removeCacheControlDirective(mixed $directive) : mixed
Parameters
- $directive : mixed
Tags
removeCookie()
Remove a specific cookie value by name
public
removeCookie(mixed $name) : self
Parameters
- $name : mixed
-
Cookie to remove by name
Return values
selfremoveHeader()
Remove a specific HTTP header.
public
removeHeader(mixed $header) : self
Parameters
- $header : mixed
-
HTTP header to remove.
Return values
selfsend()
Send the request
public
send() : Response
Return values
ResponsesetAuth()
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
selfsetClient()
Set the client used to transport the request
public
setClient(ClientInterface $client) : self
Parameters
- $client : ClientInterface
Return values
selfsetEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
selfsetHeader()
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
selfsetHeaderFactory()
Set the header factory to use to create headers
public
setHeaderFactory(HeaderFactoryInterface $factory) : self
Parameters
- $factory : HeaderFactoryInterface
Return values
selfsetHeaders()
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
selfsetHost()
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
selfsetIsRedirect()
public
setIsRedirect(mixed $isRedirect) : mixed
Use the history plugin (not emitting a warning as this is built-into the RedirectPlugin for now)
Parameters
- $isRedirect : mixed
Tags
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
selfsetPort()
Set the port that the request will be sent on
public
setPort(mixed $port) : self
Parameters
- $port : mixed
-
Port number to set
Return values
selfsetProtocolVersion()
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
selfsetResponse()
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
RequestsetScheme()
Set the URI scheme of the request (http, https, ftp, etc)
public
setScheme(mixed $scheme) : self
Parameters
- $scheme : mixed
-
Scheme to set
Return values
selfsetState()
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
setUrl()
Set the URL of the request
public
setUrl(mixed $url) : self
Parameters
- $url : mixed
-
|Url Full URL to set including query string
Return values
selfstartResponse()
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
selfgetEventArray()
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