mini\url() function

Documentation

Generate URL with proper relative path resolution and optional CDN support

Resolves paths against baseUrl (or cdnUrl if $cdn = true), handling relative paths like '..', '.', and absolute paths. Strips scheme/host from input URLs to ensure all URLs resolve against the configured base.

Examples: url('/api/users') → https://example.com/api/users url('css/style.css', cdn: true) → https://cdn.example.com/app/css/style.css url('../images/logo.png') → https://example.com/images/logo.png url('/assets/app.js', ['v' => '2']) → https://example.com/assets/app.js?v=2

Returns UriInterface which is stringable, so works in templates: <a href="<?= url('/users') ?>">Users</a>

Can chain PSR-7 methods for further manipulation: url('/posts')->withFragment('comments')->withQuery('page=2')

Signature

function url(Psr\Http\Message\UriInterface|string $path = '', array $query = array (
), bool $cdn = false): Psr\Http\Message\UriInterface

Parameters

NameTypeDefault
$path Psr\Http\Message\UriInterface|string ''
$query array array ( )
$cdn bool false

Returns

Psr\Http\Message\UriInterface

Source

functions.php:70-126