WP_CLI

WpOrgApi::json_get_request()privateWP-CLI 1.0

Execute a remote GET request.

Метод класса: WpOrgApi{}

Хуков нет.

Возвращает

Разное|false. False on failure. Decoded JSON on success.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->json_get_request( $url, $headers, $options );
$url(строка) (обязательный)
URL to execute the GET request on.
$headers(массив)
Associative array of headers.
По умолчанию: []
$options(массив)
Associative array of options.
По умолчанию: []

Код WpOrgApi::json_get_request() WP-CLI 2.8.0-alpha

private function json_get_request( $url, $headers = [], $options = [] ) {
	$headers = array_merge(
		[
			'Accept' => 'application/json',
		],
		$headers
	);

	$response = $this->get_request( $url, $headers, $options );

	if ( false === $response ) {
		return $response;
	}

	$data = json_decode( $response, true );

	if ( JSON_ERROR_NONE !== json_last_error() ) {
		throw new RuntimeException( 'Failed to decode JSON: ' . json_last_error_msg() );
	}

	return $data;
}