Documentation

UrlPackage extends Package
in package

Package that adds a base URL to asset URLs in addition to a version.

The package allows to use more than one base URLs in which case it randomly chooses one for each asset; it also guarantees that any given path will always use the same base URL to be nice with HTTP caching mechanisms.

When the request context is available, this package can choose the best base URL to use based on the current request scheme:

  • For HTTP request, it chooses between all base URLs;
  • For HTTPs requests, it chooses between HTTPs base URLs and relative protocol URLs or falls back to any base URL if no secure ones are available.
Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Properties

$baseUrls  : array<string|int, mixed>
$context  : mixed
$sslPackage  : self|null
$versionStrategy  : mixed

Methods

__construct()  : mixed
getBaseUrl()  : string
Returns the base URL for a path.
getUrl()  : string
Returns an absolute or root-relative public path.
getVersion()  : string
Returns the asset version for an asset.
chooseBaseUrl()  : int
Determines which base URL to use for the given path.
getContext()  : ContextInterface
getVersionStrategy()  : VersionStrategyInterface
isAbsoluteUrl()  : bool
getSslUrls()  : mixed

Properties

$baseUrls

private array<string|int, mixed> $baseUrls = []

$sslPackage

private self|null $sslPackage = null

$versionStrategy

private mixed $versionStrategy

Methods

getBaseUrl()

Returns the base URL for a path.

public getBaseUrl(string $path) : string
Parameters
$path : string
Return values
string

getUrl()

Returns an absolute or root-relative public path.

public getUrl(string $path) : string
Parameters
$path : string
Return values
string

getVersion()

Returns the asset version for an asset.

public getVersion(string $path) : string
Parameters
$path : string
Return values
string

chooseBaseUrl()

Determines which base URL to use for the given path.

protected chooseBaseUrl(string $path) : int

Override this method to change the default distribution strategy. This method should always return the same base URL index for a given path.

Parameters
$path : string
Return values
int

isAbsoluteUrl()

protected isAbsoluteUrl(string $url) : bool
Parameters
$url : string
Return values
bool

getSslUrls()

private getSslUrls(array<string|int, mixed> $urls) : mixed
Parameters
$urls : array<string|int, mixed>

        
On this page

Search results