Documentation

Utils
in package

FinalYes

Table of Contents

Methods

chooseHandler()  : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
Chooses and creates a default handler to use based on the environment.
debugResource()  : resource
Returns a debug stream based on the provided variable.
defaultCaBundle()  : string
Returns the default cacert bundle for the current system.
defaultUserAgent()  : string
Get the default User-Agent string to use with Guzzle.
describeType()  : string
Debug function used to describe the provided value type and class.
headersFromLines()  : array<string|int, mixed>
Parses an array of header lines into an associative array of headers.
isHostInNoProxy()  : bool
Returns true if the provided host matches any of the no proxy areas.
jsonDecode()  : object|array<string|int, mixed>|string|int|float|bool|null
Wrapper for json_decode that throws when an error occurs.
jsonEncode()  : string
Wrapper for JSON encoding that throws when an error occurs.
normalizeHeaderKeys()  : array<string|int, mixed>
Creates an associative array of lowercase header names to the actual header casing.
normalizeProtocols()  : array<string|int, string>
addStreamHandler()  : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
connectionCapOptions()  : array{max_host_connections?: int, max_total_connections?: int}
createCurlHandler()  : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
createCurlHandlerOptions()  : array<string, mixed>
getDefaultPort()  : int|null
hasConnectionCapOptions()  : bool
idnToAsci()  : string|false
ipMatchesPrefix()  : bool
isTransportSharingRequired()  : bool
matchesNoProxyList()  : bool
noProxyRuleMatches()  : bool
packIpAddress()  : string|false
parseBoundedUnsignedInteger()  : int|null
parseNoProxyCidrRule()  : array{type: string, value: string, prefix: int}|null
parseNoProxyHost()  : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
parseNoProxyHostString()  : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
parseNoProxyPort()  : int|null
parseNoProxyRule()  : array{type: string, value: string, port: int|null, matchesRoot: bool}|array{type: string, value: string, prefix: int}|null
parseNoProxyTarget()  : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
splitNoProxyHostAndPort()  : array{0: string, 1: int|null}|null

Methods

chooseHandler()

Chooses and creates a default handler to use based on the environment.

public static chooseHandler([array{transport_sharing?: mixed, max_host_connections?: mixed, max_total_connections?: mixed, multiplex?: mixed} $handlerOptions = [] ]) : callable(RequestInterface, array<string|int, mixed>): PromiseInterface

The returned handler is not wrapped by any default middlewares.

Parameters
$handlerOptions : array{transport_sharing?: mixed, max_host_connections?: mixed, max_total_connections?: mixed, multiplex?: mixed} = []

Handler constructor options.

Tags
throws
RuntimeException

if no viable Handler is available.

Return values
callable(RequestInterface, array<string|int, mixed>): PromiseInterface —

Returns the best handler for the given system.

debugResource()

Returns a debug stream based on the provided variable.

public static debugResource([mixed $value = null ]) : resource
Parameters
$value : mixed = null

Optional value

Return values
resource

defaultCaBundle()

Returns the default cacert bundle for the current system.

public static defaultCaBundle() : string

Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+.

First, the openssl.cafile and curl.cainfo php.ini settings are checked. If those settings are not configured, then the common locations for bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X and Windows are checked. If any of these file locations are found on disk, they will be utilized.

Note: the result of this function is cached for subsequent calls.

Tags
throws
RuntimeException

if no bundle can be found.

Return values
string

defaultUserAgent()

Get the default User-Agent string to use with Guzzle.

public static defaultUserAgent() : string
Return values
string

describeType()

Debug function used to describe the provided value type and class.

public static describeType(mixed $input) : string

Utils::describeType() will be removed in guzzlehttp/guzzle:8.0. Use get_debug_type() instead.

Parameters
$input : mixed
Return values
string —

Returns a string containing the type of the variable and if a class is provided, the class name.

headersFromLines()

Parses an array of header lines into an associative array of headers.

public static headersFromLines(iterable<string|int, mixed> $lines) : array<string|int, mixed>
Parameters
$lines : iterable<string|int, mixed>

Header lines array of strings in the following format: "Name: Value"

Return values
array<string|int, mixed>

isHostInNoProxy()

Returns true if the provided host matches any of the no proxy areas.

public static isHostInNoProxy(string $host, array<string|int, string> $noProxyArray) : bool

This method will strip a port from the host if it is present. Domain patterns are matched case-insensitively. Exact IP literal patterns are matched by their normalized binary address.

Areas are matched in the following cases:

  1. "*" (without quotes) always matches any hosts.
  2. An exact domain or IP literal match.
  3. A bare domain matches itself and its subdomains. e.g. 'mit.edu' will match 'mit.edu' and 'foo.mit.edu'.
  4. The area starts with "." and the area is the last part of the host. e.g. '.mit.edu' will match any host that ends with '.mit.edu'.
  5. IP CIDR entries match IP literal hosts. e.g. '192.168.0.0/16' will match '192.168.1.10' and 'fd00::/8' will match '[fd00::1]'.
Parameters
$host : string

Host to check against the patterns.

$noProxyArray : array<string|int, string>

An array of host or CIDR patterns.

Tags
throws
InvalidArgumentException
Return values
bool

jsonDecode()

Wrapper for json_decode that throws when an error occurs.

public static jsonDecode(string $json[, bool $assoc = false ][, int $depth = 512 ][, int $options = 0 ]) : object|array<string|int, mixed>|string|int|float|bool|null

Utils::jsonDecode() will be removed in guzzlehttp/guzzle:8.0. Use PHP's json_decode() instead.

Parameters
$json : string

JSON data to parse

$assoc : bool = false

When true, returned objects will be converted into associative arrays.

$depth : int = 512

User specified recursion depth.

$options : int = 0

Bitmask of JSON decode options.

Tags
throws
InvalidArgumentException

if the JSON cannot be decoded.

see
https://www.php.net/manual/en/function.json-decode.php
Return values
object|array<string|int, mixed>|string|int|float|bool|null

jsonEncode()

Wrapper for JSON encoding that throws when an error occurs.

public static jsonEncode(mixed $value[, int $options = 0 ][, int $depth = 512 ]) : string

Utils::jsonEncode() will be removed in guzzlehttp/guzzle:8.0. Use PHP's json_encode() instead.

Parameters
$value : mixed

The value being encoded

$options : int = 0

JSON encode option bitmask

$depth : int = 512

Set the maximum depth. Must be greater than zero.

Tags
throws
InvalidArgumentException

if the JSON cannot be encoded.

see
https://www.php.net/manual/en/function.json-encode.php
Return values
string

normalizeHeaderKeys()

Creates an associative array of lowercase header names to the actual header casing.

public static normalizeHeaderKeys(array<string|int, mixed> $headers) : array<string|int, mixed>
Parameters
$headers : array<string|int, mixed>
Return values
array<string|int, mixed>

normalizeProtocols()

public static normalizeProtocols(mixed $protocols) : array<string|int, string>
Parameters
$protocols : mixed
Tags
throws
InvalidArgumentException
Return values
array<string|int, string>

addStreamHandler()

private static addStreamHandler(callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null $handler, string $sharingMode, bool $sharingRequired, array{max_host_connections?: int, max_total_connections?: int} $connectionCapOptions) : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
Parameters
$handler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
$sharingMode : string
$sharingRequired : bool
$connectionCapOptions : array{max_host_connections?: int, max_total_connections?: int}
Return values
callable(RequestInterface, array<string|int, mixed>): PromiseInterface

connectionCapOptions()

private static connectionCapOptions(array{max_host_connections?: mixed, max_total_connections?: mixed} $handlerOptions) : array{max_host_connections?: int, max_total_connections?: int}
Parameters
$handlerOptions : array{max_host_connections?: mixed, max_total_connections?: mixed}
Return values
array{max_host_connections?: int, max_total_connections?: int}

createCurlHandler()

private static createCurlHandler(string $sharingMode, array{max_host_connections?: mixed, max_total_connections?: mixed, multiplex?: mixed} $handlerOptions) : callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null
Parameters
$sharingMode : string
$handlerOptions : array{max_host_connections?: mixed, max_total_connections?: mixed, multiplex?: mixed}
Return values
callable(RequestInterface, array<string|int, mixed>): PromiseInterface|null

createCurlHandlerOptions()

private static createCurlHandlerOptions(string $sharingMode) : array<string, mixed>
Parameters
$sharingMode : string
Return values
array<string, mixed>

getDefaultPort()

private static getDefaultPort(string $scheme) : int|null
Parameters
$scheme : string
Return values
int|null

hasConnectionCapOptions()

private static hasConnectionCapOptions(array{max_host_connections?: mixed, max_total_connections?: mixed} $handlerOptions) : bool
Parameters
$handlerOptions : array{max_host_connections?: mixed, max_total_connections?: mixed}
Return values
bool

idnToAsci()

private static idnToAsci(string $domain, int $options[, array<string|int, mixed>|null &$info = [] ]) : string|false
Parameters
$domain : string
$options : int
$info : array<string|int, mixed>|null = []
Return values
string|false

ipMatchesPrefix()

private static ipMatchesPrefix(string $address, string $network, int $prefix) : bool
Parameters
$address : string
$network : string
$prefix : int
Return values
bool

isTransportSharingRequired()

private static isTransportSharingRequired(string $sharingMode) : bool
Parameters
$sharingMode : string
Return values
bool

matchesNoProxyList()

private static matchesNoProxyList(array{type: string, value: string, port: int|null, matchesRoot: bool} $target, array<string|int, mixed> $noProxy) : bool
Parameters
$target : array{type: string, value: string, port: int|null, matchesRoot: bool}
$noProxy : array<string|int, mixed>
Return values
bool

noProxyRuleMatches()

private static noProxyRuleMatches(array{type: string, value: string, port: int|null, matchesRoot: bool} $target, array{type: string, value: string, port?: int|null, matchesRoot?: bool, prefix?: int|null} $rule) : bool
Parameters
$target : array{type: string, value: string, port: int|null, matchesRoot: bool}
$rule : array{type: string, value: string, port?: int|null, matchesRoot?: bool, prefix?: int|null}
Return values
bool

packIpAddress()

private static packIpAddress(string $ip) : string|false
Parameters
$ip : string
Return values
string|false

parseBoundedUnsignedInteger()

private static parseBoundedUnsignedInteger(string $value, int $max) : int|null
Parameters
$value : string
$max : int
Return values
int|null

parseNoProxyCidrRule()

private static parseNoProxyCidrRule(string $area) : array{type: string, value: string, prefix: int}|null
Parameters
$area : string
Return values
array{type: string, value: string, prefix: int}|null

parseNoProxyHost()

private static parseNoProxyHost(string $host, int|null $port, bool $matchesRoot) : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
Parameters
$host : string
$port : int|null
$matchesRoot : bool
Return values
array{type: string, value: string, port: int|null, matchesRoot: bool}|null

parseNoProxyHostString()

private static parseNoProxyHostString(string $host) : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
Parameters
$host : string
Return values
array{type: string, value: string, port: int|null, matchesRoot: bool}|null

parseNoProxyPort()

private static parseNoProxyPort(string $port) : int|null
Parameters
$port : string
Return values
int|null

parseNoProxyRule()

private static parseNoProxyRule(string $area) : array{type: string, value: string, port: int|null, matchesRoot: bool}|array{type: string, value: string, prefix: int}|null
Parameters
$area : string
Return values
array{type: string, value: string, port: int|null, matchesRoot: bool}|array{type: string, value: string, prefix: int}|null

parseNoProxyTarget()

private static parseNoProxyTarget(UriInterface $uri) : array{type: string, value: string, port: int|null, matchesRoot: bool}|null
Parameters
$uri : UriInterface
Return values
array{type: string, value: string, port: int|null, matchesRoot: bool}|null

splitNoProxyHostAndPort()

private static splitNoProxyHostAndPort(string $area) : array{0: string, 1: int|null}|null
Parameters
$area : string
Return values
array{0: string, 1: int|null}|null
On this page

Search results