added theme support
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user