instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -12,39 +12,39 @@ class TenantAvatarService
private const SIZES = [64, 128, 256];
private const DEFAULT_SIZE = 128;
public static function isValidUuid(string $uuid): bool
public function isValidUuid(string $uuid): bool
{
return self::imageIsValidUuid($uuid);
}
public static function storageBase(): string
public function storageBase(): string
{
return self::imageStorageBase();
}
public static function tenantDir(string $uuid): string
public function tenantDir(string $uuid): string
{
return self::storageBase() . '/tenants/' . $uuid . '/avatar';
return $this->storageBase() . '/tenants/' . $uuid . '/avatar';
}
public static function findAvatarPath(string $uuid, ?int $size = null): ?string
public function findAvatarPath(string $uuid, ?int $size = null): ?string
{
if (!self::isValidUuid($uuid)) {
if (!$this->isValidUuid($uuid)) {
return null;
}
$dirs = self::avatarDirs($uuid);
$dirs = $this->avatarDirs($uuid);
foreach ($dirs as $dir) {
if (!is_dir($dir)) {
continue;
}
if ($size) {
$size = self::normalizeSize($size);
$variant = self::findVariantPath($dir, $size);
$size = $this->normalizeSize($size);
$variant = $this->findVariantPath($dir, $size);
if ($variant) {
return $variant;
}
}
$defaultVariant = self::findVariantPath($dir, self::DEFAULT_SIZE);
$defaultVariant = $this->findVariantPath($dir, self::DEFAULT_SIZE);
if ($defaultVariant) {
return $defaultVariant;
}
@@ -56,18 +56,18 @@ class TenantAvatarService
return null;
}
public static function hasAvatar(string $uuid): bool
public function hasAvatar(string $uuid): bool
{
$path = self::findAvatarPath($uuid);
$path = $this->findAvatarPath($uuid);
return $path ? is_file($path) : false;
}
public static function delete(string $uuid): bool
public function delete(string $uuid): bool
{
if (!self::isValidUuid($uuid)) {
if (!$this->isValidUuid($uuid)) {
return false;
}
foreach (self::avatarDirs($uuid) as $dir) {
foreach ($this->avatarDirs($uuid) as $dir) {
if (!is_dir($dir)) {
continue;
}
@@ -85,9 +85,9 @@ class TenantAvatarService
return true;
}
public static function saveUpload(string $uuid, array $file): array
public function saveUpload(string $uuid, array $file): array
{
if (!self::isValidUuid($uuid)) {
if (!$this->isValidUuid($uuid)) {
return ['ok' => false, 'error' => t('Tenant not found')];
}
if (empty($file) || !isset($file['tmp_name'])) {
@@ -101,7 +101,7 @@ class TenantAvatarService
}
$tmpPath = $file['tmp_name'];
$mime = self::detectMime($tmpPath);
$mime = $this->detectMime($tmpPath);
$isSvg = self::imageIsSvgUpload($mime, $tmpPath);
$ext = self::imageExtensionForMime($mime, $isSvg);
if (!$ext) {
@@ -111,12 +111,12 @@ class TenantAvatarService
return ['ok' => false, 'error' => t('Invalid image file')];
}
$dir = self::tenantDir($uuid);
$dir = $this->tenantDir($uuid);
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
return ['ok' => false, 'error' => t('Upload failed')];
}
self::delete($uuid);
$this->delete($uuid);
$originalPath = $dir . '/original.' . $ext;
if (!move_uploaded_file($tmpPath, $originalPath)) {
return ['ok' => false, 'error' => t('Upload failed')];
@@ -134,12 +134,12 @@ class TenantAvatarService
return ['ok' => true, 'path' => $originalPath, 'mime' => $mime];
}
public static function detectMime(string $path): string
public function detectMime(string $path): string
{
return self::imageDetectMime($path);
}
private static function normalizeSize(int $size): int
private function normalizeSize(int $size): int
{
if (in_array($size, self::SIZES, true)) {
return $size;
@@ -147,7 +147,7 @@ class TenantAvatarService
return self::DEFAULT_SIZE;
}
private static function findVariantPath(string $dir, int $size): ?string
private function findVariantPath(string $dir, int $size): ?string
{
$matches = glob($dir . '/avatar-' . $size . '.*');
if (!$matches) {
@@ -159,18 +159,18 @@ class TenantAvatarService
return $matches[0] ?? null;
}
private static function avatarDirs(string $uuid): array
private function avatarDirs(string $uuid): array
{
$dirs = [self::tenantDir($uuid)];
$legacy = self::legacyTenantDir($uuid);
$dirs = [$this->tenantDir($uuid)];
$legacy = $this->legacyTenantDir($uuid);
if ($legacy !== $dirs[0]) {
$dirs[] = $legacy;
}
return $dirs;
}
private static function legacyTenantDir(string $uuid): string
private function legacyTenantDir(string $uuid): string
{
return self::storageBase() . '/tenants/' . $uuid;
return $this->storageBase() . '/tenants/' . $uuid;
}
}