WC_REST_Authentication::parse_header()publicWC 3.0.0

Parse the Authorization header into parameters.

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

Хуков нет.

Возвращает

Массив. Map of parameter values.

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

$WC_REST_Authentication = new WC_REST_Authentication();
$WC_REST_Authentication->parse_header( $header );
$header(строка) (обязательный)
Authorization header value (not including "Authorization: " prefix).

Список изменений

С версии 3.0.0 Введена.

Код WC_REST_Authentication::parse_header() WC 8.7.0

public function parse_header( $header ) {
	if ( 'OAuth ' !== substr( $header, 0, 6 ) ) {
		return array();
	}

	// From OAuth PHP library, used under MIT license.
	$params = array();
	if ( preg_match_all( '/(oauth_[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches ) ) {
		foreach ( $matches[1] as $i => $h ) {
			$params[ $h ] = urldecode( empty( $matches[3][ $i ] ) ? $matches[4][ $i ] : $matches[3][ $i ] );
		}
		if ( isset( $params['realm'] ) ) {
			unset( $params['realm'] );
		}
	}

	return $params;
}