PHP Класс yii\httpclient\Client

С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\base\Component
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
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:

Приватные методы

Метод Описание
createRequestShortcut ( string $method, string $url, array | string $data, array $headers, array $options ) : Request

Описание методов

afterSend() публичный Метод

The method will trigger the [[EVENT_AFTER_SEND]] event.
С версии: 2.0.1
public afterSend ( Request $request, Response $response )
$request Request request instance.
$response Response received response instance.

batchSend() публичный Метод

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.
Результат Response[] responses list.

beforeSend() публичный Метод

The method will trigger the [[EVENT_BEFORE_SEND]] event.
С версии: 2.0.1
public beforeSend ( Request $request )
$request Request request instance.

createRequest() публичный Метод

public createRequest ( ) : Request
Результат Request request instance.

createRequestLogToken() публичный Метод

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.
Результат string log token.

createResponse() публичный Метод

Creates a response instance.
public createResponse ( string $content = null, array $headers = [] ) : Response
$content string raw content
$headers array headers list.
Результат Response request instance.

delete() публичный Метод

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.
Результат Request request instance.

get() публичный Метод

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.
Результат Request request instance.

getFormatter() публичный Метод

Returns HTTP message formatter instance for the specified format.
public getFormatter ( string $format ) : yii\httpclient\FormatterInterface
$format string format name.
Результат yii\httpclient\FormatterInterface formatter instance.

getParser() публичный Метод

Returns HTTP message parser instance for the specified format.
public getParser ( string $format ) : yii\httpclient\ParserInterface
$format string format name
Результат yii\httpclient\ParserInterface parser instance.

getTransport() публичный Метод

public getTransport ( ) : Transport
Результат Transport HTTP message transport instance.

head() публичный Метод

Creates 'HEAD' request.
public head ( string $url, array $headers = [], array $options = [] ) : Request
$url string target URL.
$headers array request headers.
$options array request options.
Результат Request request instance.

options() публичный Метод

Creates 'OPTIONS' request.
public options ( string $url, array $options = [] ) : Request
$url string target URL.
$options array request options.
Результат Request request instance.

patch() публичный Метод

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.
Результат Request request instance.

post() публичный Метод

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.
Результат Request request instance.

put() публичный Метод

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.
Результат Request request instance.

send() публичный Метод

Performs given request.
public send ( Request $request ) : Response
$request Request request to be sent.
Результат Response response instance.

setTransport() публичный Метод

- 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

Описание свойств

$baseUrl публичное свойство

base request URL.
public $baseUrl

$contentLoggingMaxSize публичное свойство

maximum symbols count of the request content, which should be taken to compose a log and profile messages. Exceeding content will be truncated.
См. также: createRequestLogToken()
public $contentLoggingMaxSize

$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.
public $formatters

$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.
public $parsers

$requestConfig публичное свойство

request object configuration.
public $requestConfig

$responseConfig публичное свойство

response config configuration.
public $responseConfig