AssetVariantProvider
in package
Image variant plan per asset type (= usage, e.g. `blog-articles`) plus the global watermark.
The plan is read from the DB tables cms_system_asset_variants, cms_system_asset_usages and
cms_system_asset_usage_variants through AssetVariantManager::findPlanMap(): one query
per request, then an in-memory memo (no shared cache, so nothing to invalidate).
The neon parameters.assetVariants (config/Shared/assetVariants.neon) is a fallback, used
when the tables are missing or the query fails (code deployed before migrations), or when a
usage has no DB row or no active assigned variant. A fallback is written to the assets log.
Result shape: array<folder, {maxWidth, maxHeight, resizeFlags, useWatermark}> in assignment
order with original last, plus the keys variant, alias and original (the renderer
ignores them; they are written to Asset::variants).
IMPORTANT: the plan is read in-process without RBAC (not via ApiBridge). Anonymous front-end uploads need the plan, and RBAC v2 through ApiBridge would return a silent empty result, so the site would quietly run from neon.
Table of Contents
Properties
-
$dbPlans
: array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: list
, useWatermark: bool, variant: string|null, alias: string|null, original?: bool}>>|null - $dbUnavailable : bool
- The DB could not be read (missing tables or query error); tried only once per request.
- $fallbackTypes : array<string, true>
- $variantManager : AssetVariantManager|null
- $variants : array<string|int, mixed>
- $watermarkPath : array<string|int, mixed>
Methods
- __construct() : mixed
- getFallbackTypes() : array<int, string>
- Types that fell back to neon in this request (contract harness, diagnostics).
- getVariants() : array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>
- getVariantsByAssetPath() : array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>
- Derives the variant set from the file location (`asset.path`). For legacy assets without a variant plan stored in the entity, typically a video uploaded before the upload pipeline started storing the plan.
- getWatermarkPath() : array{rel: string, abs: string}
- Paths to the watermark image: global, one for the whole project.
- resetCache() : void
- Drops the memo; only for harnesses and tests, managers never call it.
-
loadDbPlans()
: array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: list
, useWatermark: bool, variant: string|null, alias: string|null, original?: bool}>>|null - log() : void
- Logs to the `assets` channel; a logging failure must not break the upload (fail-soft).
Properties
$dbPlans
private
array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: list, useWatermark: bool, variant: string|null, alias: string|null, original?: bool}>>|null
$dbPlans
= null
plan memo from the DB (null = not read yet)
$dbUnavailable
The DB could not be read (missing tables or query error); tried only once per request.
private
bool
$dbUnavailable
= false
$fallbackTypes
private
array<string, true>
$fallbackTypes
= []
types that fell back to neon in this request
$variantManager read-only
private
AssetVariantManager|null
$variantManager
= null
$variants read-only
private
array<string|int, mixed>
$variants
$watermarkPath read-only
private
array<string|int, mixed>
$watermarkPath
Methods
__construct()
public
__construct(array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool}>> $variants, array{rel: string, abs: string} $watermarkPath[, AssetVariantManager|null $variantManager = null ]) : mixed
Parameters
- $variants : array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool}>>
-
neon (fallback)
- $watermarkPath : array{rel: string, abs: string}
- $variantManager : AssetVariantManager|null = null
getFallbackTypes()
Types that fell back to neon in this request (contract harness, diagnostics).
public
getFallbackTypes() : array<int, string>
Return values
array<int, string>getVariants()
public
getVariants(string $type) : array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>
Parameters
- $type : string
Return values
array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>getVariantsByAssetPath()
Derives the variant set from the file location (`asset.path`). For legacy assets without a variant plan stored in the entity, typically a video uploaded before the upload pipeline started storing the plan.
public
getVariantsByAssetPath(string $assetPath) : array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>
Parameters
- $assetPath : string
Return values
array<string, array{maxWidth: int, maxHeight: int, resizeFlags: int[], useWatermark: bool, variant?: string|null, alias?: string|null, original?: bool}>getWatermarkPath()
Paths to the watermark image: global, one for the whole project.
public
getWatermarkPath() : array{rel: string, abs: string}
Return values
array{rel: string, abs: string}resetCache()
Drops the memo; only for harnesses and tests, managers never call it.
public
resetCache() : void
loadDbPlans()
private
loadDbPlans() : array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: list, useWatermark: bool, variant: string|null, alias: string|null, original?: bool}>>|null
Return values
array<string, array<string, array{maxWidth: int, maxHeight: int, resizeFlags: listnull = the DB cannot be read
log()
Logs to the `assets` channel; a logging failure must not break the upload (fail-soft).
private
log(string|Throwable $message) : void
Parameters
- $message : string|Throwable