class AvatarUploader

Constants

SIZES

Sizes to generate: base (1×), @2x, @3x.

Properties

protected Cloud $uploadDir

Methods

__construct(Factory $filesystemFactory)

No description

void
uploadPresized(User $user, ImageInterface $image1x, ImageInterface|null $image2x, ImageInterface|null $image3x)

Upload pre-sized avatar images provided by an OAuth driver.

void
upload(User $user, ImageInterface $image)

No description

void
removeFileAfterSave(User $user)

Handle the removal of the old avatar file after a successful user save.

void
remove(User $user)

No description

void
deleteAllVariants(string $basePath)

Delete the base file and all HiDPI variants (@2x, @3x) for a given base path.

string|null
srcsetFor(string $basePath)

Return the srcset string for a given base path, including only variants that exist on disk.

array
variantPaths(string $basePath)

Return all variant paths (base + @2x + @3x) for a given base path.

string
variantPath(string $basePath, string $suffix)

Derive a variant path from the base path and a suffix (e.g. '' → 'abc.webp', '@2x' → 'abc@2x.webp').

Details

__construct(Factory $filesystemFactory)

Parameters

Factory $filesystemFactory

void uploadPresized(User $user, ImageInterface $image1x, ImageInterface|null $image2x, ImageInterface|null $image3x)

Upload pre-sized avatar images provided by an OAuth driver.

The caller is responsible for providing correctly sized images. Only the variants whose images are non-null are stored.

Parameters

User $user
ImageInterface $image1x Base (1×) image
ImageInterface|null $image2x 2× image (200px), or null to skip
ImageInterface|null $image3x 3× image (300px), or null to skip

Return Value

void

void upload(User $user, ImageInterface $image)

Parameters

User $user
ImageInterface $image

Return Value

void

protected void removeFileAfterSave(User $user)

Handle the removal of the old avatar file after a successful user save.

We don't place this in remove() because otherwise we would call changeAvatarPath 2 times when uploading.

Parameters

User $user

Return Value

void

void remove(User $user)

Parameters

User $user

Return Value

void

void deleteAllVariants(string $basePath)

Delete the base file and all HiDPI variants (@2x, @3x) for a given base path.

Safe to call with external URLs — the filesystem exists() check guards against it.

Parameters

string $basePath

Return Value

void

string|null srcsetFor(string $basePath)

Return the srcset string for a given base path, including only variants that exist on disk.

Returns null if only the base file exists (no HiDPI variants).

Parameters

string $basePath

Return Value

string|null

protected array variantPaths(string $basePath)

Return all variant paths (base + @2x + @3x) for a given base path.

Parameters

string $basePath

Return Value

array

protected string variantPath(string $basePath, string $suffix)

Derive a variant path from the base path and a suffix (e.g. '' → 'abc.webp', '@2x' → 'abc@2x.webp').

Parameters

string $basePath
string $suffix

Return Value

string