Files
2026-10-20 10:27:30 +01:00

66 lines
1.4 KiB
PHP

<?php
namespace Modules\Stylist\Services;
use App\Models\SiteSetting;
final class SiteSettingsRepository
{
/**
* Retrieve a SonarDesk site setting.
*
* The scope argument is retained for compatibility with Stylist.
*/
public function get(
string $key,
mixed $default = null,
string $scope = 'site'
): mixed {
$this->validateScope($scope);
$value = SiteSetting::valueFor($key);
return $value ?? $default;
}
/**
* Persist a SonarDesk site setting.
*
* The type and public arguments are retained for compatibility
* with Stylist's existing theme management API.
*/
public function put(
string $key,
mixed $value,
string $scope = 'site',
string $type = 'string',
bool $public = true
): void {
$this->validateScope($scope);
SiteSetting::put(
$key,
$value === null ? null : (string) $value
);
}
/**
* Return all site settings as an associative array.
*/
public function site(): array
{
return SiteSetting::query()
->pluck('value', 'key')
->all();
}
private function validateScope(string $scope): void
{
if ($scope !== 'site') {
throw new \InvalidArgumentException(
"Unsupported settings scope: {$scope}"
);
}
}
}