class UrlService (View source)

Service for building absolute URLs

This service provides consistent URL building across the application, supporting both configured base URLs and auto-detection from HTTP headers.

Methods

__construct(ConfigurationInterface $config, LoggerInterface|null $logger = null)

No description

string
getAbsoluteUrl(string $path)

Build an absolute URL from a relative path

string|null
getEmailUrl(string $path)

Build an absolute URL for use inside outbound emails

string
getBaseUrl()

Get the base URL for the application

string
getLoginUrl()

Get the login page URL

string|null
getZoneEditUrl(int $zoneId)

Get a zone edit URL for use inside outbound emails

Details

__construct(ConfigurationInterface $config, LoggerInterface|null $logger = null)

No description

Parameters

ConfigurationInterface $config
LoggerInterface|null $logger

string getAbsoluteUrl(string $path)

Build an absolute URL from a relative path

Priority order for base URL:

  1. Configured application_url (if set)
  2. A localhost base built from the detected protocol and base path prefix

Parameters

string $path

Relative path (e.g., '/zones/123/edit')

Return Value

string

Full absolute URL (e.g., 'https://example.com/poweradmin/zones/123/edit')

string|null getEmailUrl(string $path)

Build an absolute URL for use inside outbound emails

Only uses the configured interface.application_url. HTTP_HOST and other request-time headers are intentionally ignored so that an emailed link cannot be redirected by a forged Host header.

Parameters

string $path

Relative path (e.g., '/password/reset?token=...')

Return Value

string|null

Full absolute URL, or null if application_url is not configured

string getBaseUrl()

Get the base URL for the application

Returns the full base URL including protocol, host, and base path prefix. Uses configured URL if available, otherwise auto-detects from server variables.

Return Value

string

Base URL (e.g., 'https://example.com/poweradmin')

string getLoginUrl()

Get the login page URL

Convenience method for building login URL.

Return Value

string

Full URL to login page

string|null getZoneEditUrl(int $zoneId)

Get a zone edit URL for use inside outbound emails

Parameters

int $zoneId

Zone ID

Return Value

string|null

Full URL to zone edit page, or null if application_url is not configured