AssetSrcset
in package
FinalYes
Builds `srcset` from image variants. Pure logic without disk or entity access, so it is tested standalone. Variant files come from `Asset::getVariantFiles()`, the set of existing folders is supplied by the caller ({@see \App\UI\Front\System\Components\AssetRendererComponent\AssetRenderer}).
Rules:
- the original is left out of
srcset(it has no size cap, it is a rescue, not a candidate); - only variants with a real width from
metacount:maxWidthis an upper bound, not a width, and awdescriptor with a false width would make the browser choose wrongly; - one candidate per width (a shrink-only variant gives a small photo the same width in
several variants); the one with the smaller
maxWidthis kept; - fewer than two candidates give an empty result (nothing to choose from, so a plain
<img>).
Table of Contents
Methods
- build() : string
- Returns the `srcset` attribute value (`url 400w, url 1200w`); an empty string means no `srcset`.
- candidates() : array<int, array{folder: string, width: int}>
- Returns `srcset` candidates ascending by width.
- __construct() : mixed
Methods
build()
Returns the `srcset` attribute value (`url 400w, url 1200w`); an empty string means no `srcset`.
public
static build(array<int, array{folder: string, width: ?int, maxWidth: int, original: bool}> $files, array<int, string>|null $existing, callable(string): string $urlOf) : string
Parameters
- $files : array<int, array{folder: string, width: ?int, maxWidth: int, original: bool}>
- $existing : array<int, string>|null
- $urlOf : callable(string): string
-
file URL by folder
Return values
stringcandidates()
Returns `srcset` candidates ascending by width.
public
static candidates(array<int, array{folder: string, width: ?int, maxWidth: int, original: bool}> $files[, array<int, string>|null $existing = null ]) : array<int, array{folder: string, width: int}>
Parameters
- $files : array<int, array{folder: string, width: ?int, maxWidth: int, original: bool}>
-
output of
Asset::getVariantFiles() - $existing : array<int, string>|null = null
-
folders whose file exists; null = no filtering
Return values
array<int, array{folder: string, width: int}>__construct()
private
__construct() : mixed