API / Minn\Support / Url

Url final class

Minn\Support\Url · public/minn/src/Minn/Support/Url.php · 271 lines

URL shaping the escaping and query helpers share: the character cleanup esc_url applies, bracket encoding outside the authority, and query argument merging. Behaviour pinned by contracts/fixtures/api/functions.json.

Public

staticwithTrailingSlash(string $value): string#

The value with one trailing slash, whatever slashes or backslashes it ended in (trailingslashit).

staticwithoutTrailingSlash(string $value): string#

The value with every trailing slash and backslash taken off (untrailingslashit).

staticclean(string $url, string $scheme = 'http'): string#

Spaces encoded, stray characters dropped, ";//" healed, a bare host given http; '' when nothing survives.

staticencodeBrackets(string $url, array $parsed): string#

Square brackets after the authority are percent-encoded; the authority itself is left alone. @param array<string, mixed> $parsed

$parsedarray<string, mixed>
staticwithQuery(string $uri, array $new, Closure $encode, Closure $build): string#

The URI with query arguments merged in (false removes one), the fragment kept, a bare query string treated as such; a URI that is only a query (or nothing) keeps its leading question mark.

$newarray<string, mixed>
$encodeClosure(array): arrayencodes the existing arguments the way the reference does
$buildClosure(array): stringbuilds the query string
staticvalidateForHttp(string $url, string $homeHost, int $homePort, Closure $externalAllowed, ?Closure $safePorts = NULL): ?string#

The checks wp_http_validate_url makes on a URL whose protocol already passed: an http(s) scheme, a host without credentials or a colon, no private address unless it is this site or allowed, only the safe ports (80, 443 and 8080 unless the caller's list says otherwise; the site's own always). Returns the URL, or null when refused.

$externalAllowedClosure(string, string): boolwhether a private host may be fetched anyway
$safePorts(Closure(list<int>, string, string): array)|nullthe port list for a URL that names a port
staticbuildQuery(array $data, string $prefix = ''): string#

A query string in the reference's spelling (probe query-args): keys and values as given, nested keys as `a%5Bb%5D`, null left out, booleans as 0/1.

staticparse(string $url, int $component = -1): array|string|int|false|null#

parse_url that also accepts scheme-relative and path-only URLs; a single component by its PHP_URL_* constant.

staticwithScheme(string $url, string $scheme): string#

The URL under a scheme, or scheme-and-host stripped for 'relative'; a protocol-relative URL is read as http first.

staticsafeRedirect(string $location, Closure $allowedHosts, string $requestPath = ''): ?string#

A redirect target the site may send a browser to: http(s) only and a host the caller allows. A relative one stays on the site: a path without a leading slash is put after the request path's folder (up to its last "/", the dots kept), anything else as given. Credentials before the host are kept unless they hold an "@" (probe functions-formatting-doubts).

$allowedHostsClosure(string): list<string>the hosts allowed for the target's host
staticabsolute(string $relative, string $base): string#

A reference made absolute against a base URL, as WP_Http resolves a redirect's Location: one with a scheme stays as it is, "//host" takes the base's scheme, a path without a leading slash joins the base's folder with its "../" steps folded, and no path keeps the base's.

Internals 1

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateisPrivate(array $p): bool#

Whether an IPv4 address is one a request must not reach: anything outside the global range (private, loopback, link-local, shared CGNAT space with the clouds' metadata hosts, benchmarking, documentation, reserved), the old 6to4 relays and multicast, as the reference refuses them.

$plist<int>