instances added god may help
This commit is contained in:
@@ -12,30 +12,30 @@ class BrandingLogoService
|
||||
private const SIZES = [64, 128, 256];
|
||||
private const DEFAULT_SIZE = 128;
|
||||
|
||||
public static function storageBase(): string
|
||||
public function storageBase(): string
|
||||
{
|
||||
return self::imageStorageBase();
|
||||
}
|
||||
|
||||
public static function brandingDir(): string
|
||||
public function brandingDir(): string
|
||||
{
|
||||
return self::storageBase() . '/branding/logo';
|
||||
return $this->storageBase() . '/branding/logo';
|
||||
}
|
||||
|
||||
public static function findLogoPath(?int $size = null): ?string
|
||||
public function findLogoPath(?int $size = null): ?string
|
||||
{
|
||||
$dir = self::brandingDir();
|
||||
$dir = $this->brandingDir();
|
||||
if (!is_dir($dir)) {
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -43,15 +43,15 @@ class BrandingLogoService
|
||||
return $original ?: null;
|
||||
}
|
||||
|
||||
public static function hasLogo(): bool
|
||||
public function hasLogo(): bool
|
||||
{
|
||||
$path = self::findLogoPath();
|
||||
$path = $this->findLogoPath();
|
||||
return $path ? is_file($path) : false;
|
||||
}
|
||||
|
||||
public static function delete(): bool
|
||||
public function delete(): bool
|
||||
{
|
||||
$dir = self::brandingDir();
|
||||
$dir = $this->brandingDir();
|
||||
if (!is_dir($dir)) {
|
||||
return true;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ class BrandingLogoService
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function saveUpload(array $file): array
|
||||
public function saveUpload(array $file): array
|
||||
{
|
||||
if (empty($file) || !isset($file['tmp_name'])) {
|
||||
return ['ok' => false, 'error' => t('No file uploaded')];
|
||||
@@ -81,7 +81,7 @@ class BrandingLogoService
|
||||
}
|
||||
|
||||
$tmpPath = $file['tmp_name'];
|
||||
$mime = self::detectMime($tmpPath);
|
||||
$mime = $this->detectMime($tmpPath);
|
||||
$isSvg = self::imageIsSvgUpload($mime, $tmpPath);
|
||||
$ext = self::imageExtensionForMime($mime, $isSvg);
|
||||
if (!$ext) {
|
||||
@@ -91,12 +91,12 @@ class BrandingLogoService
|
||||
return ['ok' => false, 'error' => t('Invalid image file')];
|
||||
}
|
||||
|
||||
$dir = self::brandingDir();
|
||||
$dir = $this->brandingDir();
|
||||
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
|
||||
return ['ok' => false, 'error' => t('Upload failed')];
|
||||
}
|
||||
|
||||
self::delete();
|
||||
$this->delete();
|
||||
$originalPath = $dir . '/original.' . $ext;
|
||||
if (!move_uploaded_file($tmpPath, $originalPath)) {
|
||||
return ['ok' => false, 'error' => t('Upload failed')];
|
||||
@@ -114,12 +114,12 @@ class BrandingLogoService
|
||||
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;
|
||||
@@ -127,7 +127,7 @@ class BrandingLogoService
|
||||
return self::DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
private static function findVariantPath(string $dir, int $size): ?string
|
||||
private function findVariantPath(string $dir, int $size): ?string
|
||||
{
|
||||
$matches = glob($dir . '/logo-' . $size . '.*');
|
||||
if (!$matches) {
|
||||
|
||||
Reference in New Issue
Block a user