PHP Class yii\httpclient\Client

Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Component
Datei anzeigen Open project: yiisoft/yii2-httpclient Class Usage Examples

Public Properties

Property Type Description
$baseUrl base request URL.
$contentLoggingMaxSize maximum symbols count of the request content, which should be taken to compose a log and profile messages. Exceeding content will be truncated.
$formatters the formatters for converting data into the content of the specified [[format]]. The array keys are the format names, and the array values are the corresponding configurations for creating the formatter objects.
$parsers the parsers for converting content of the specified [[format]] into the data. The array keys are the format names, and the array values are the corresponding configurations for creating the parser objects.
$requestConfig request object configuration.
$responseConfig response config configuration.

Public Methods

Method Description
afterSend ( Request $request, Response $response ) This method is invoked right after request is sent.
batchSend ( array $requests ) : Response[] Performs multiple HTTP requests in parallel.
beforeSend ( Request $request ) This method is invoked right before request is sent.
createRequest ( ) : Request
createRequestLogToken ( string $method, string $url, array $headers, string $content ) : string Composes the log/profiling message token for the given HTTP request parameters.
createResponse ( string $content = null, array $headers = [] ) : Response Creates a response instance.
delete ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request Creates 'DELETE' request.
get ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request Creates 'GET' request.
getFormatter ( string $format ) : yii\httpclient\FormatterInterface Returns HTTP message formatter instance for the specified format.
getParser ( string $format ) : yii\httpclient\ParserInterface Returns HTTP message parser instance for the specified format.
getTransport ( ) : Transport
head ( string $url, array $headers = [], array $options = [] ) : Request Creates 'HEAD' request.
options ( string $url, array $options = [] ) : Request Creates 'OPTIONS' request.
patch ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request Creates 'PATCH' request.
post ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request Creates 'POST' request.
put ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request Creates 'PUT' request.
send ( Request $request ) : Response Performs given request.
setTransport ( Transport | array | string $transport ) Sets the HTTP message transport. It can be specified in one of the following forms:

Private Methods

Method Description
createRequestShortcut ( string $method, string $url, array | string $data, array $headers, array $options ) : Request

Method Details

afterSend() public method

The method will trigger the [[EVENT_AFTER_SEND]] event.
Since: 2.0.1
public afterSend ( Request $request, Response $response )
$request Request request instance.
$response Response received response instance.

batchSend() public method

This method accepts an array of the Request objects and returns an array of the Response objects. Keys of the response array correspond the ones from request array. php $client = new Client(); $requests = [ 'news' => $client->get('http://domain.com/news'), 'friends' => $client->get('http://domain.com/user/friends', ['userId' => 12]), ]; $responses = $client->batchSend($requests); var_dump($responses['news']->isOk); var_dump($responses['friends']->isOk);
public batchSend ( array $requests ) : Response[]
$requests array requests to perform.
return Response[] responses list.

beforeSend() public method

The method will trigger the [[EVENT_BEFORE_SEND]] event.
Since: 2.0.1
public beforeSend ( Request $request )
$request Request request instance.

createRequest() public method

public createRequest ( ) : Request
return Request request instance.

createRequestLogToken() public method

This method should be used by transports during request sending logging.
public createRequestLogToken ( string $method, string $url, array $headers, string $content ) : string
$method string request method name.
$url string request URL.
$headers array request headers.
$content string request content.
return string log token.

createResponse() public method

Creates a response instance.
public createResponse ( string $content = null, array $headers = [] ) : Response
$content string raw content
$headers array headers list.
return Response request instance.

delete() public method

Creates 'DELETE' request.
public delete ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.

get() public method

Creates 'GET' request.
public get ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.

getFormatter() public method

Returns HTTP message formatter instance for the specified format.
public getFormatter ( string $format ) : yii\httpclient\FormatterInterface
$format string format name.
return yii\httpclient\FormatterInterface formatter instance.

getParser() public method

Returns HTTP message parser instance for the specified format.
public getParser ( string $format ) : yii\httpclient\ParserInterface
$format string format name
return yii\httpclient\ParserInterface parser instance.

getTransport() public method

public getTransport ( ) : Transport
return Transport HTTP message transport instance.

head() public method

Creates 'HEAD' request.
public head ( string $url, array $headers = [], array $options = [] ) : Request
$url string target URL.
$headers array request headers.
$options array request options.
return Request request instance.

options() public method

Creates 'OPTIONS' request.
public options ( string $url, array $options = [] ) : Request
$url string target URL.
$options array request options.
return Request request instance.

patch() public method

Creates 'PATCH' request.
public patch ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.

post() public method

Creates 'POST' request.
public post ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.

put() public method

Creates 'PUT' request.
public put ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.

send() public method

Performs given request.
public send ( Request $request ) : Response
$request Request request to be sent.
return Response response instance.

setTransport() public method

- an instance of Transport: actual transport object to be used - a string: representing the class name of the object to be created - a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties - a PHP callable: either an anonymous function or an array representing a class method ([$class or $object, $method]). The callable should return a new instance of the object being created.
public setTransport ( Transport | array | string $transport )
$transport Transport | array | string HTTP message transport

Property Details

$baseUrl public_oe property

base request URL.
public $baseUrl

$contentLoggingMaxSize public_oe property

maximum symbols count of the request content, which should be taken to compose a log and profile messages. Exceeding content will be truncated.
See also: createRequestLogToken()
public $contentLoggingMaxSize

$formatters public_oe property

the formatters for converting data into the content of the specified [[format]]. The array keys are the format names, and the array values are the corresponding configurations for creating the formatter objects.
public $formatters

$parsers public_oe property

the parsers for converting content of the specified [[format]] into the data. The array keys are the format names, and the array values are the corresponding configurations for creating the parser objects.
public $parsers

$requestConfig public_oe property

request object configuration.
public $requestConfig

$responseConfig public_oe property

response config configuration.
public $responseConfig