mirror of
https://github.com/pelican-dev/panel.git
synced 2025-06-11 13:49:00 +02:00
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Extensions\Avatar;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AvatarProvider
|
|
{
|
|
/** @var AvatarSchemaInterface[] */
|
|
private array $providers = [];
|
|
|
|
/**
|
|
* @return AvatarSchemaInterface[] | AvatarSchemaInterface | null
|
|
*/
|
|
public function get(?string $id = null): array|AvatarSchemaInterface|null
|
|
{
|
|
return $id ? array_get($this->providers, $id) : $this->providers;
|
|
}
|
|
|
|
public function getActiveSchema(): ?AvatarSchemaInterface
|
|
{
|
|
return $this->get(config('panel.filament.avatar-provider'));
|
|
}
|
|
|
|
public function getAvatarUrl(User $user): ?string
|
|
{
|
|
if (config('panel.filament.uploadable-avatars')) {
|
|
$path = "avatars/$user->id.png";
|
|
|
|
if (Storage::disk('public')->exists($path)) {
|
|
return Storage::url($path);
|
|
}
|
|
}
|
|
|
|
return $this->getActiveSchema()?->get($user);
|
|
}
|
|
|
|
public function register(AvatarSchemaInterface $provider): void
|
|
{
|
|
if (array_key_exists($provider->getId(), $this->providers)) {
|
|
return;
|
|
}
|
|
|
|
$this->providers[$provider->getId()] = $provider;
|
|
}
|
|
}
|