Oihana PHP System

documentUrl.php

Table of Contents

Functions

documentUrl()  : string
Generates a full document URL based on the project's base URL.

Functions

documentUrl()

Generates a full document URL based on the project's base URL.

documentUrl([string $path = Char::EMPTY ][, ContainerInterface|null $container = null ][, string|null $definition = 'baseUrl' ][, bool $trailingSlash = false ]) : string

This helper function is commonly used in IoC container definitions of models to generate the accessible URL of a document or resource.

The function:

  1. Retrieves the base URL from the DI container using the provided definition key (default 'baseUrl').
  2. Joins the base URL with the provided relative path.
  3. Optionally appends a trailing slash.

Example usage:

use Psr\Container\ContainerInterface;

$url = documentUrl('uploads/image.png', $container);
// returns something like 'https://example.com/uploads/image.png'

$urlWithSlash = documentUrl('uploads', $container, 'baseUrl', true);
// returns 'https://example.com/uploads/'
Parameters
$path : string = Char::EMPTY

Relative path of the document (default: empty string).

$container : ContainerInterface|null = null

Optional DI container to fetch the base URL from.

$definition : string|null = 'baseUrl'

Key used to fetch the base URL from the container (default: 'baseUrl').

$trailingSlash : bool = false

Whether to append a trailing slash to the resulting URL (default: false).

Tags
throws
ContainerExceptionInterface

If an error occurs while retrieving the base URL from the container.

throws
NotFoundExceptionInterface

If the base URL definition is not found in the container.

Return values
string

The fully resolved document URL.


        
On this page

Search results