Client
extends AbstractHttp
in package
implements
ClientInterface
HTTP client class
Tags
Table of Contents
Interfaces
- ClientInterface
Properties
- $auth : Auth|null
- HTTP auth object
- $handler : HandlerInterface|null
- Request handler
- $middleware : array<string|int, mixed>
- Registered middleware, in registration order (first-registered = outermost)
- $multiHandler : CurlMulti|null
- Request multi-handler
- $options : array<string|int, mixed>
- Client options
- $request : AbstractRequest|null
- Request
- $response : AbstractResponse|null
- Response
Methods
- __call() : Response|Promise|array<string|int, mixed>|string
- Magic method to send requests by the method name, i.e. $client->get('http://localhost/');
- __callStatic() : Response|Promise|array<string|int, mixed>|string
- Magic method to send requests by the static method name, i.e. Client::get('http://localhost/');
- __construct() : mixed
- Instantiate the client object
- __toString() : string
- To string magic method to render the client request to a raw string
- addData() : Client
- Add data
- addFile() : Client
- Add file
- addHeader() : Client
- Add header
- addHeaders() : Client
- Add headers
- addMiddleware() : Client
- Add a middleware to the pipeline. A plain callable is wrapped in CallableMiddleware automatically. Registration order is wrap order: the first-registered middleware is outermost.
- addOption() : Client
- Add an option
- addOptions() : Client
- Add options
- addQuery() : Client
- Add query
- createMulti() : CurlMulti
- Factory to create a multi-handler object
- dispatch() : Response|array<string|int, mixed>|string
- Perform the actual synchronous dispatch, always - unlike send(), this does NOT redirect to sendAsync() when the 'async' option is set. Promise::wait()/ resolve() call this (not send()) to perform the real request: since a Promise wraps a Client whose 'async' option is still true for the lifetime of that Client, calling send() from inside wait()/resolve() would re-enter the async branch above and return a brand-new Promise instead of ever dispatching.
- dispatchRequest() : Response
- Perform the actual handler dispatch for the given request - the terminal handler at the center of the middleware pipeline. If $request is a Client\Request, it's re-pointed as $this->request first, so any middleware-applied modifications (e.g. an injected header) are reflected in what's actually sent. A foreign (non-Client\Request) PSR-7 request is converted first, reusing the same conversion sendRequest() uses.
- fromCurlCommand() : Client
- Method to convert Curl CLI command to a client object
- getAuth() : Auth|null
- Get auth
- getBody() : Body|null
- Get request body
- getBodyContent() : string|null
- Get request body content
- getBodyContentLength() : int
- Get request body content length
- getData() : mixed
- Get data
- getFile() : string|null
- Get file
- getFiles() : array<string|int, mixed>|null
- Get files
- getHandler() : HandlerInterface|null
- Get handler
- getHeader() : mixed
- Get header
- getHeaders() : mixed
- Get headers
- getMethod() : string|null
- Get method
- getMiddleware() : array<string|int, mixed>
- Get the registered middleware, in registration order
- getMultiHandler() : CurlMulti
- Get multi-handler
- getOption() : mixed
- Get options
- getOptions() : array<string|int, mixed>
- Get options
- getQuery() : mixed
- Get query
- getRequest() : Request
- Get the request
- getResponse() : Response
- Get the response
- getType() : mixed
- Get type
- hasAuth() : bool
- Has auth
- hasBody() : bool
- Has request body
- hasData() : bool
- Has data
- hasFile() : bool
- Has file
- hasFiles() : bool
- Has files
- hasHandler() : bool
- Has handler
- hasHeader() : bool
- Has header
- hasHeaders() : bool
- Has headers
- hasMethod() : bool
- Has method
- hasMiddleware() : bool
- Has any middleware registered
- hasMultiHandler() : bool
- Has multi-handler
- hasOption() : bool
- Has option
- hasOptions() : bool
- Has options
- hasQuery() : bool
- Has query
- hasRequest() : bool
- Has request
- hasResponse() : bool
- Get the response
- hasType() : bool
- Has type
- isAccepted() : bool|null
- Determine if the response is 202 accepted
- isBadGateway() : bool|null
- Determine if the response is a 502 Bad Gateway
- isBadRequest() : bool|null
- Determine if the response is a 400 Bad Request
- isClientError() : bool|null
- Determine if the response is a client error
- isComplete() : bool
- Determine if the response is complete
- isConflict() : bool|null
- Determine if the response is a 409 Conflict
- isContinue() : bool|null
- Determine if the response is a continue
- isCreated() : bool|null
- Determine if the response is 201 created
- isError() : bool|null
- Determine if the response is an error
- isForbidden() : bool|null
- Determine if the response is a 403 Forbidden
- isFound() : bool|null
- Determine if the response is a 302 Found
- isInternalServerError() : bool|null
- Determine if the response is a 500 Internal Server Error
- isLengthRequired() : bool|null
- Determine if the response is a 411 Length Required
- isMethodNotAllowed() : bool|null
- Determine if the response is a 405 Method Not Allowed
- isMovedPermanently() : bool|null
- Determine if the response is a 301 Moved Permanently
- isNoContent() : bool|null
- Determine if the response is 204 No Content
- isNotAcceptable() : bool|null
- Determine if the response is a 406 Not Acceptable
- isNotFound() : bool|null
- Determine if the response is a 404 Not Found
- isOk() : bool|null
- Determine if the response is 200 OK
- isRedirect() : bool|null
- Determine if the response is a redirect
- isRequestTimeout() : bool|null
- Determine if the response is a 408 Request Timeout
- isServerError() : bool|null
- Determine if the response is a server error
- isServiceUnavailable() : bool|null
- Determine if the response is a 503 Service Unavailable
- isSuccess() : bool|null
- Determine if the response is a success
- isTooManyRequests() : bool|null
- Determine if the response is a 429 Too Many Requests
- isUnauthorized() : bool|null
- Determine if the response is a 401 Unauthorized
- isUnprocessableEntity() : bool|null
- Determine if the response is a 422 Unprocessable Entity
- isUnsupportedMediaType() : bool|null
- Determine if the response is a 415 Unsupported Media Type
- prepare() : Client
- Prepare the client request
- removeAllData() : Client
- Remove all data
- removeAllHeaders() : Client
- Remove all headers
- removeAllQuery() : Client
- Remove all query data
- removeBody() : Client
- Remove the body
- removeData() : Client
- Remove data
- removeFile() : Client
- Remove file
- removeFiles() : Client
- Remove all files
- removeHeader() : Client
- Remove header
- removeOption() : Client
- Remove option
- removeOptions() : Client
- Remove options
- removeQuery() : Client
- Remove query
- removeType() : Client
- Remove type
- render() : string
- Method to render the request as a string
- reset() : static
- Method to reset the client
- send() : Response|Promise|array<string|int, mixed>|string
- Send the client request
- sendAsync() : Promise
- Method to send the request asynchronously
- sendRequest() : ResponseInterface
- Send a PSR-7 request and return a PSR-7 response, per PSR-18
- setAuth() : Client
- Set auth
- setBody() : Client
- Set request body
- setBodyFromFile() : Client
- Set request body from file
- setData() : Client
- Set data
- setFiles() : Client
- Set files
- setHandler() : Client
- Set handler
- setHeaders() : Client
- Set headers (clear out any existing headers)
- setMethod() : Client
- Set method
- setMultiHandler() : Client
- Set multi-handler
- setOptions() : Client
- Set options
- setQuery() : Client
- Set query
- setRequest() : Client
- Set the request object
- setResponse() : AbstractHttp
- Set the response
- setType() : Client
- Set type
- toCurlCommand() : string
- Method to convert client object to a Curl command for the CLI
- convertToClientRequest() : Request
- Convert a foreign (non-Client\Request) PSR-7 RequestInterface into a Client\Request. A Client\Request passed in is returned as-is. Shared by sendRequest() (the PSR-18 entry point) and dispatchRequest() (so a middleware that substitutes a foreign PSR-7 request is honored rather than silently dropped).
- processMiddleware() : Response
- Run the request through the middleware pipeline (if any), terminating in dispatchRequest(). Shared by dispatch() and sendRequest() so middleware behaves identically regardless of entry point.
- request() : Request
- Get the client's request, materializing an empty one if none exists yet - every data-touching setter goes through this, so there is exactly one place a Client\Request gets created on demand instead of the old options-array-vs-request dual bookkeeping.
- syncRequestFromOptions() : void
- Push request-shaped options ('type', 'headers', 'query', 'data', 'files') onto the client's request, if one exists. Options are configuration that seeds the request the moment both are available - they are not a second, parallel data store - so this is the one place that seeding happens, called any time the request or the options change.
Properties
$auth
HTTP auth object
protected
Auth|null
$auth
= null
$handler
Request handler
protected
HandlerInterface|null
$handler
= null
$middleware
Registered middleware, in registration order (first-registered = outermost)
protected
array<string|int, mixed>
$middleware
= []
$multiHandler
Request multi-handler
protected
CurlMulti|null
$multiHandler
= null
$options
Client options
protected
array<string|int, mixed>
$options
= []
$request
Request
protected
AbstractRequest|null
$request
= null
$response
Response
protected
AbstractResponse|null
$response
= null
Methods
__call()
Magic method to send requests by the method name, i.e. $client->get('http://localhost/');
public
__call(string $methodName, array<string|int, mixed> $arguments) : Response|Promise|array<string|int, mixed>|string
Parameters
- $methodName : string
- $arguments : array<string|int, mixed>
Tags
Return values
Response|Promise|array<string|int, mixed>|string__callStatic()
Magic method to send requests by the static method name, i.e. Client::get('http://localhost/');
public
static __callStatic(string $methodName, array<string|int, mixed> $arguments) : Response|Promise|array<string|int, mixed>|string
Parameters
- $methodName : string
- $arguments : array<string|int, mixed>
Tags
Return values
Response|Promise|array<string|int, mixed>|string__construct()
Instantiate the client object
public
__construct() : mixed
Optional parameters are
- Request URI string
- Client request instance
- Client response instance
- Client handler instance
- Auth instance
- Options array
__toString()
To string magic method to render the client request to a raw string
public
__toString() : string
Return values
stringaddData()
Add data
public
addData(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientaddFile()
Add file
public
addFile(string $file[, string|null $name = null ]) : Client
Parameters
- $file : string
- $name : string|null = null
Tags
Return values
ClientaddHeader()
Add header
public
addHeader(Header|string|int $header[, mixed $value = null ]) : Client
Parameters
- $header : Header|string|int
- $value : mixed = null
Return values
ClientaddHeaders()
Add headers
public
addHeaders(array<string|int, mixed> $headers) : Client
Parameters
- $headers : array<string|int, mixed>
Return values
ClientaddMiddleware()
Add a middleware to the pipeline. A plain callable is wrapped in CallableMiddleware automatically. Registration order is wrap order: the first-registered middleware is outermost.
public
addMiddleware(MiddlewareInterface|callable $middleware) : Client
Parameters
- $middleware : MiddlewareInterface|callable
Return values
ClientaddOption()
Add an option
public
addOption(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientaddOptions()
Add options
public
addOptions(array<string|int, mixed> $options) : Client
Parameters
- $options : array<string|int, mixed>
Return values
ClientaddQuery()
Add query
public
addQuery(string $name, mixed $value) : Client
Parameters
- $name : string
- $value : mixed
Return values
ClientcreateMulti()
Factory to create a multi-handler object
public
static createMulti(array<string|int, mixed> $requests[, CurlMulti $multiHandler = new ClientHandlerCurlMulti() ]) : CurlMulti
Parameters
- $requests : array<string|int, mixed>
- $multiHandler : CurlMulti = new ClientHandlerCurlMulti()
Return values
CurlMultidispatch()
Perform the actual synchronous dispatch, always - unlike send(), this does NOT redirect to sendAsync() when the 'async' option is set. Promise::wait()/ resolve() call this (not send()) to perform the real request: since a Promise wraps a Client whose 'async' option is still true for the lifetime of that Client, calling send() from inside wait()/resolve() would re-enter the async branch above and return a brand-new Promise instead of ever dispatching.
public
dispatch([string|null $uri = null ][, string|null $method = null ]) : Response|array<string|int, mixed>|string
Parameters
- $uri : string|null = null
- $method : string|null = null
Tags
Return values
Response|array<string|int, mixed>|stringdispatchRequest()
Perform the actual handler dispatch for the given request - the terminal handler at the center of the middleware pipeline. If $request is a Client\Request, it's re-pointed as $this->request first, so any middleware-applied modifications (e.g. an injected header) are reflected in what's actually sent. A foreign (non-Client\Request) PSR-7 request is converted first, reusing the same conversion sendRequest() uses.
public
dispatchRequest(RequestInterface $request) : Response
Note: this is public (so a terminal callable passed into Pipeline::process() can reach it), but it assumes prepare() has already run - it does not create a handler itself, and depends on $this->handler already being set.
Parameters
- $request : RequestInterface
Tags
Return values
ResponsefromCurlCommand()
Method to convert Curl CLI command to a client object
public
static fromCurlCommand(string $command) : Client
Parameters
- $command : string
Tags
Return values
ClientgetAuth()
Get auth
public
getAuth() : Auth|null
Return values
Auth|nullgetBody()
Get request body
public
getBody() : Body|null
Return values
Body|nullgetBodyContent()
Get request body content
public
getBodyContent() : string|null
Return values
string|nullgetBodyContentLength()
Get request body content length
public
getBodyContentLength([bool $mb = false ]) : int
Parameters
- $mb : bool = false
Return values
intgetData()
Get data
public
getData([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getFile()
Get file
public
getFile(string $key) : string|null
Parameters
- $key : string
Return values
string|nullgetFiles()
Get files
public
getFiles() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetHandler()
Get handler
public
getHandler() : HandlerInterface|null
Return values
HandlerInterface|nullgetHeader()
Get header
public
getHeader(string $name) : mixed
Parameters
- $name : string
getHeaders()
Get headers
public
getHeaders() : mixed
getMethod()
Get method
public
getMethod() : string|null
Return values
string|nullgetMiddleware()
Get the registered middleware, in registration order
public
getMiddleware() : array<string|int, mixed>
Return values
array<string|int, mixed>getMultiHandler()
Get multi-handler
public
getMultiHandler() : CurlMulti
Return values
CurlMultigetOption()
Get options
public
getOption(string $name) : mixed
Parameters
- $name : string
getOptions()
Get options
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getQuery()
Get query
public
getQuery([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getRequest()
Get the request
public
getRequest() : Request
Tags
Return values
RequestgetResponse()
Get the response
public
getResponse() : Response
Tags
Return values
ResponsegetType()
Get type
public
getType() : mixed
hasAuth()
Has auth
public
hasAuth() : bool
Return values
boolhasBody()
Has request body
public
hasBody() : bool
Return values
boolhasData()
Has data
public
hasData([string|null $key = null ]) : bool
Parameters
- $key : string|null = null
Return values
boolhasFile()
Has file
public
hasFile(string $key) : bool
Parameters
- $key : string
Return values
boolhasFiles()
Has files
public
hasFiles() : bool
Return values
boolhasHandler()
Has handler
public
hasHandler() : bool
Return values
boolhasHeader()
Has header
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolhasHeaders()
Has headers
public
hasHeaders() : bool
Return values
boolhasMethod()
Has method
public
hasMethod() : bool
Return values
boolhasMiddleware()
Has any middleware registered
public
hasMiddleware() : bool
Return values
boolhasMultiHandler()
Has multi-handler
public
hasMultiHandler() : bool
Return values
boolhasOption()
Has option
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolhasOptions()
Has options
public
hasOptions() : bool
Return values
boolhasQuery()
Has query
public
hasQuery([string|null $key = null ]) : bool
Parameters
- $key : string|null = null
Return values
boolhasRequest()
Has request
public
hasRequest() : bool
Return values
boolhasResponse()
Get the response
public
hasResponse() : bool
Return values
boolhasType()
Has type
public
hasType() : bool
Return values
boolisAccepted()
Determine if the response is 202 accepted
public
isAccepted() : bool|null
Return values
bool|nullisBadGateway()
Determine if the response is a 502 Bad Gateway
public
isBadGateway() : bool|null
Return values
bool|nullisBadRequest()
Determine if the response is a 400 Bad Request
public
isBadRequest() : bool|null
Return values
bool|nullisClientError()
Determine if the response is a client error
public
isClientError() : bool|null
Return values
bool|nullisComplete()
Determine if the response is complete
public
isComplete() : bool
Return values
boolisConflict()
Determine if the response is a 409 Conflict
public
isConflict() : bool|null
Return values
bool|nullisContinue()
Determine if the response is a continue
public
isContinue() : bool|null
Return values
bool|nullisCreated()
Determine if the response is 201 created
public
isCreated() : bool|null
Return values
bool|nullisError()
Determine if the response is an error
public
isError() : bool|null
Return values
bool|nullisForbidden()
Determine if the response is a 403 Forbidden
public
isForbidden() : bool|null
Return values
bool|nullisFound()
Determine if the response is a 302 Found
public
isFound() : bool|null
Return values
bool|nullisInternalServerError()
Determine if the response is a 500 Internal Server Error
public
isInternalServerError() : bool|null
Return values
bool|nullisLengthRequired()
Determine if the response is a 411 Length Required
public
isLengthRequired() : bool|null
Return values
bool|nullisMethodNotAllowed()
Determine if the response is a 405 Method Not Allowed
public
isMethodNotAllowed() : bool|null
Return values
bool|nullisMovedPermanently()
Determine if the response is a 301 Moved Permanently
public
isMovedPermanently() : bool|null
Return values
bool|nullisNoContent()
Determine if the response is 204 No Content
public
isNoContent() : bool|null
Return values
bool|nullisNotAcceptable()
Determine if the response is a 406 Not Acceptable
public
isNotAcceptable() : bool|null
Return values
bool|nullisNotFound()
Determine if the response is a 404 Not Found
public
isNotFound() : bool|null
Return values
bool|nullisOk()
Determine if the response is 200 OK
public
isOk() : bool|null
Return values
bool|nullisRedirect()
Determine if the response is a redirect
public
isRedirect() : bool|null
Return values
bool|nullisRequestTimeout()
Determine if the response is a 408 Request Timeout
public
isRequestTimeout() : bool|null
Return values
bool|nullisServerError()
Determine if the response is a server error
public
isServerError() : bool|null
Return values
bool|nullisServiceUnavailable()
Determine if the response is a 503 Service Unavailable
public
isServiceUnavailable() : bool|null
Return values
bool|nullisSuccess()
Determine if the response is a success
public
isSuccess() : bool|null
Return values
bool|nullisTooManyRequests()
Determine if the response is a 429 Too Many Requests
public
isTooManyRequests() : bool|null
Return values
bool|nullisUnauthorized()
Determine if the response is a 401 Unauthorized
public
isUnauthorized() : bool|null
Return values
bool|nullisUnprocessableEntity()
Determine if the response is a 422 Unprocessable Entity
public
isUnprocessableEntity() : bool|null
Return values
bool|nullisUnsupportedMediaType()
Determine if the response is a 415 Unsupported Media Type
public
isUnsupportedMediaType() : bool|null
Return values
bool|nullprepare()
Prepare the client request
public
prepare([string|null $uri = null ][, string|null $method = null ]) : Client
Parameters
- $uri : string|null = null
- $method : string|null = null
Tags
Return values
ClientremoveAllData()
Remove all data
public
removeAllData() : Client
Return values
ClientremoveAllHeaders()
Remove all headers
public
removeAllHeaders() : Client
Return values
ClientremoveAllQuery()
Remove all query data
public
removeAllQuery() : Client
Return values
ClientremoveBody()
Remove the body
public
removeBody() : Client
Return values
ClientremoveData()
Remove data
public
removeData(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveFile()
Remove file
public
removeFile(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveFiles()
Remove all files
public
removeFiles() : Client
Return values
ClientremoveHeader()
Remove header
public
removeHeader(string $name) : Client
Parameters
- $name : string
Return values
ClientremoveOption()
Remove option
public
removeOption(string $name) : Client
Parameters
- $name : string
Return values
ClientremoveOptions()
Remove options
public
removeOptions() : Client
Return values
ClientremoveQuery()
Remove query
public
removeQuery(string $key) : Client
Parameters
- $key : string
Return values
ClientremoveType()
Remove type
public
removeType() : Client
Return values
Clientrender()
Method to render the request as a string
public
render() : string
Return values
stringreset()
Method to reset the client
public
reset([bool $data = true ][, bool $headers = false ][, bool $clear = false ]) : static
Parameters
- $data : bool = true
- $headers : bool = false
- $clear : bool = false
Return values
staticsend()
Send the client request
public
send([string|null $uri = null ][, string|null $method = null ]) : Response|Promise|array<string|int, mixed>|string
Parameters
- $uri : string|null = null
- $method : string|null = null
Tags
Return values
Response|Promise|array<string|int, mixed>|stringsendAsync()
Method to send the request asynchronously
public
sendAsync() : Promise
Return values
PromisesendRequest()
Send a PSR-7 request and return a PSR-7 response, per PSR-18
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Tags
Return values
ResponseInterfacesetAuth()
Set auth
public
setAuth(Auth $auth) : Client
Parameters
- $auth : Auth
Return values
ClientsetBody()
Set request body
public
setBody(string $body) : Client
Parameters
- $body : string
Tags
Return values
ClientsetBodyFromFile()
Set request body from file
public
setBodyFromFile(string $file) : Client
Parameters
- $file : string
Tags
Return values
ClientsetData()
Set data
public
setData(array<string|int, mixed> $data) : Client
Parameters
- $data : array<string|int, mixed>
Return values
ClientsetFiles()
Set files
public
setFiles(array<string|int, mixed>|string $files[, bool $multipart = true ]) : Client
Parameters
- $files : array<string|int, mixed>|string
- $multipart : bool = true
Tags
Return values
ClientsetHandler()
Set handler
public
setHandler(HandlerInterface $handler) : Client
Parameters
- $handler : HandlerInterface
Return values
ClientsetHeaders()
Set headers (clear out any existing headers)
public
setHeaders(array<string|int, mixed> $headers) : Client
Parameters
- $headers : array<string|int, mixed>
Return values
ClientsetMethod()
Set method
public
setMethod(string $method) : Client
Parameters
- $method : string
Return values
ClientsetMultiHandler()
Set multi-handler
public
setMultiHandler(CurlMulti $multiHandler) : Client
Parameters
- $multiHandler : CurlMulti
Return values
ClientsetOptions()
Set options
public
setOptions(array<string|int, mixed> $options) : Client
Supported options
- 'base_uri'
- 'method'
- 'headers'
- 'user_agent'
- 'query' (can only be encoded query string on the URI)
- 'data' (can be any request data)
- 'files'
- 'type'
- 'auto'
- 'async'
- 'verify_peer'
- 'allow_self_signed'
- 'no_content_length'
- 'raw_data'
- 'force_custom_method' (Curl only - forces CURLOPT_CUSTOMREQUEST)
Parameters
- $options : array<string|int, mixed>
Return values
ClientsetQuery()
Set query
public
setQuery(array<string|int, mixed> $query) : Client
Parameters
- $query : array<string|int, mixed>
Return values
ClientsetRequest()
Set the request object
public
setRequest(AbstractRequest $request) : Client
Overrides AbstractHttp::setRequest() so that any options already set on this client (via the constructor or setOptions()/addOption()) get synced onto a request that arrives via a direct setRequest() call - not just one materialized internally by prepare(). Without this, options set before an explicit setRequest() call were silently dropped, since syncRequestFromOptions() is a no-op until a request exists.
Parameters
- $request : AbstractRequest
Return values
ClientsetResponse()
Set the response
public
setResponse(AbstractResponse $response) : AbstractHttp
Parameters
- $response : AbstractResponse
Return values
AbstractHttpsetType()
Set type
public
setType(string $type[, bool $addHeader = true ]) : Client
Parameters
- $type : string
- $addHeader : bool = true
Return values
ClienttoCurlCommand()
Method to convert client object to a Curl command for the CLI
public
toCurlCommand() : string
Tags
Return values
stringconvertToClientRequest()
Convert a foreign (non-Client\Request) PSR-7 RequestInterface into a Client\Request. A Client\Request passed in is returned as-is. Shared by sendRequest() (the PSR-18 entry point) and dispatchRequest() (so a middleware that substitutes a foreign PSR-7 request is honored rather than silently dropped).
protected
convertToClientRequest(RequestInterface $request) : Request
Parameters
- $request : RequestInterface
Tags
Return values
RequestprocessMiddleware()
Run the request through the middleware pipeline (if any), terminating in dispatchRequest(). Shared by dispatch() and sendRequest() so middleware behaves identically regardless of entry point.
protected
processMiddleware(RequestInterface $request) : Response
MiddlewareInterface::process() is typed to the broader PSR-7 ResponseInterface (see that interface's docblock), but this method's return type is narrowed to Client\Response, since that's the concrete type Client's internals require. If a middleware short-circuits with some other ResponseInterface implementation, that mismatch is caught below and re-thrown as a clear Client\Exception rather than surfacing as a raw TypeError.
Parameters
- $request : RequestInterface
Tags
Return values
Responserequest()
Get the client's request, materializing an empty one if none exists yet - every data-touching setter goes through this, so there is exactly one place a Client\Request gets created on demand instead of the old options-array-vs-request dual bookkeeping.
protected
request() : Request
Return values
RequestsyncRequestFromOptions()
Push request-shaped options ('type', 'headers', 'query', 'data', 'files') onto the client's request, if one exists. Options are configuration that seeds the request the moment both are available - they are not a second, parallel data store - so this is the one place that seeding happens, called any time the request or the options change.
protected
syncRequestFromOptions() : void
'query' and 'data' are merged onto the request key-by-key (addQuery()/addData()), not replaced wholesale (setQuery()/setData()) - this method can run again later (e.g. from a later addOption() call for an unrelated key), and a wholesale replace would silently wipe out any data/query values added directly in between via addData()/addQuery() or a prior sync. 'headers' and 'files' are naturally merge-safe already (addHeaders()/addData() key on name), and 'type' is guarded to apply only once (first request type wins).