2023-04-14 09:33:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use CodeIgniter\HTTP\URI;
|
|
|
|
use Modules\Media\Config\Media;
|
|
|
|
|
|
|
|
if (! function_exists('media_url')) {
|
|
|
|
/**
|
|
|
|
* Returns a media URL as defined by the Media config.
|
|
|
|
*
|
|
|
|
* @param array|string $relativePath URI string or array of URI segments
|
|
|
|
*/
|
|
|
|
function media_url($relativePath = '', ?string $scheme = null): string
|
|
|
|
{
|
|
|
|
// Convert array of segments to a string
|
|
|
|
if (is_array($relativePath)) {
|
|
|
|
$relativePath = implode('/', $relativePath);
|
|
|
|
}
|
|
|
|
|
2023-08-26 13:03:01 +00:00
|
|
|
$uri = new URI(rtrim(config(Media::class)->baseURL, '/') . '/' . ltrim($relativePath));
|
2023-04-14 09:33:52 +00:00
|
|
|
|
|
|
|
return URI::createURIString(
|
|
|
|
$scheme ?? $uri->getScheme(),
|
|
|
|
$uri->getAuthority(),
|
|
|
|
$uri->getPath(),
|
|
|
|
$uri->getQuery(),
|
|
|
|
$uri->getFragment()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|