AssetFormatRegistry
in package
Single source of truth for which formats can be uploaded.
Callers always say which kinds of media they want in a given context
(AssetFormatKind), not concrete extensions. A category icon thus allows Raster and
Vector, a discussion attachment Raster and Video; SVG from an end user never gets
anywhere just because another part of the system can handle it.
$kinds is a required parameter on purpose: an implicit "allow everything" is exactly how SVG
would silently reach modules where nobody expects it.
Table of Contents
Constants
- EXTENSION_ALIASES : array<string|int, mixed> = ['jfif' => 'jpg', 'jpe' => 'jpg', 'jif' => 'jpg']
- Extensions that are just another name for the same format. `jfif` is a plain JPEG (Windows and Outlook sometimes save it so); renaming is enough, the bytes match.
Properties
- $byExtension : array<string, AssetFormatProcessor>
- $processors : array<string|int, mixed>
Methods
- __construct() : mixed
- findProcessor() : AssetFormatProcessor|null
- getExtensions() : array<int, string>
- Extensions including aliases: for `accept` (HTML also takes `.jfif`) and for checks in uploaders that validate by extension, not by MIME.
- getMimeTypes() : array<int, string>
- MIME types for the uploaders' `accept` attributes, so the client offers exactly what the server accepts.
- resolveExtension() : string|null
- Determines, from the uploaded file name, the normalized extension under which it is stored.
Constants
EXTENSION_ALIASES
Extensions that are just another name for the same format. `jfif` is a plain JPEG (Windows and Outlook sometimes save it so); renaming is enough, the bytes match.
private
array<string|int, mixed>
EXTENSION_ALIASES
= ['jfif' => 'jpg', 'jpe' => 'jpg', 'jif' => 'jpg']
Properties
$byExtension
private
array<string, AssetFormatProcessor>
$byExtension
= []
extension to processor
$processors read-only
private
array<string|int, mixed>
$processors
Methods
__construct()
public
__construct(array<int, AssetFormatProcessor> $processors) : mixed
Parameters
- $processors : array<int, AssetFormatProcessor>
findProcessor()
public
findProcessor(string $extension, array<int, AssetFormatKind> $kinds) : AssetFormatProcessor|null
Parameters
- $extension : string
- $kinds : array<int, AssetFormatKind>
Return values
AssetFormatProcessor|nullgetExtensions()
Extensions including aliases: for `accept` (HTML also takes `.jfif`) and for checks in uploaders that validate by extension, not by MIME.
public
getExtensions(array<int, AssetFormatKind> $kinds) : array<int, string>
Parameters
- $kinds : array<int, AssetFormatKind>
Return values
array<int, string>getMimeTypes()
MIME types for the uploaders' `accept` attributes, so the client offers exactly what the server accepts.
public
getMimeTypes(array<int, AssetFormatKind> $kinds) : array<int, string>
Parameters
- $kinds : array<int, AssetFormatKind>
Return values
array<int, string>resolveExtension()
Determines, from the uploaded file name, the normalized extension under which it is stored.
public
resolveExtension(string $fileName, array<int, AssetFormatKind> $kinds) : string|null
Returns null when the format is unknown or not allowed in the given context; the caller then
discards the file. Renaming an unknown extension to .jpg was silent and dangerous: SVG would
end up as a .jpg with markup content.
Parameters
- $fileName : string
- $kinds : array<int, AssetFormatKind>