Files
mesreleves-php/app/Services/SiteSettingsService.php
T
yann64 6a73a2f001 Gestion utilisateurs, limites recherche, filtres lieux/sources, fix logo prod
- Admin : CRUD complet utilisateurs (créer, modifier nom/email/mdp/rôle, supprimer)
  avec garde-fous (dernier admin, compte propre)
- Recherche : limite configurable par l'admin (défaut 200), bannière d'avertissement
  quand la limite est atteinte, plus de pagination (résultats en bloc)
- Lieux : liste non chargée sans filtre actif (performance sur grands volumes)
- Sources : idem pour admin/responsables ; membres voient toujours leurs sources
- Logo 404 prod : +FollowSymLinks dans .htaccess, storage:link dans l'assistant
  d'installation, bouton "Recréer le lien" dans Administration → Paramètres

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-07 03:39:06 +02:00

105 lines
3.4 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Storage;
class SiteSettingsService
{
private static function path(): string
{
return storage_path('app/site_settings.json');
}
private static function load(): array
{
$path = self::path();
if (! file_exists($path)) {
return [];
}
return json_decode(file_get_contents($path), true) ?: [];
}
private static function save(array $settings): void
{
file_put_contents(self::path(), json_encode($settings, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
public static function get(string $key, mixed $default = null): mixed
{
return self::load()[$key] ?? $default;
}
public static function set(string $key, mixed $value): void
{
$settings = self::load();
$settings[$key] = $value;
self::save($settings);
}
public static function all(): array
{
return self::load();
}
// ── Logo ─────────────────────────────────────────────────────────────────
public static function logoUrl(): ?string
{
$logoPath = self::get('logo_path');
if (! $logoPath) {
return null;
}
try {
if (! Storage::disk('public')->exists($logoPath)) {
return null;
}
return Storage::disk('public')->url($logoPath);
} catch (\Exception) {
return null;
}
}
// ── SMTP ─────────────────────────────────────────────────────────────────
public static function smtpConfig(): array
{
return self::get('smtp', []);
}
public static function smtpConfigured(): bool
{
$smtp = self::smtpConfig();
return ! empty($smtp['host']) && ! empty($smtp['port']);
}
// ── Titre du site ─────────────────────────────────────────────────────────
public static function siteName(): string
{
return self::get('site_name') ?: config('app.name', 'MesRelevés');
}
// ── Inscriptions ─────────────────────────────────────────────────────────
public static function registrationEnabled(): bool
{
// Désactivées par défaut
return (bool) self::get('registration_enabled', false);
}
// ── Recherche ────────────────────────────────────────────────────────────────
public static function searchMaxResults(): int
{
return max(10, (int) self::get('search_max_results', 200));
}
// ── Mises à jour ──────────────────────────────────────────────────────────
public static function updatesDisabled(): bool
{
return (bool) self::get('updates_disabled', false);
}
}