instances added god may help
This commit is contained in:
@@ -2,14 +2,22 @@
|
||||
|
||||
namespace MintyPHP\Service\Settings;
|
||||
|
||||
use MintyPHP\Repository\Settings\SettingRepository;
|
||||
use MintyPHP\Repository\Tenant\TenantRepository;
|
||||
use MintyPHP\Repository\Access\RoleRepository;
|
||||
use MintyPHP\Repository\Org\DepartmentRepository;
|
||||
use MintyPHP\Repository\Settings\SettingRepository;
|
||||
use MintyPHP\Repository\Tenant\TenantRepository;
|
||||
use MintyPHP\Support\Crypto;
|
||||
|
||||
class SettingService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SettingRepository $settingRepository,
|
||||
private readonly TenantRepository $tenantRepository,
|
||||
private readonly RoleRepository $roleRepository,
|
||||
private readonly DepartmentRepository $departmentRepository,
|
||||
private readonly ThemeConfigService $themeConfigService
|
||||
) {
|
||||
}
|
||||
public const DEFAULT_TENANT_KEY = 'default_tenant_id';
|
||||
public const DEFAULT_ROLE_KEY = 'default_role_id';
|
||||
public const DEFAULT_DEPARTMENT_KEY = 'default_department_id';
|
||||
@@ -43,112 +51,112 @@ class SettingService
|
||||
private const USER_INACTIVITY_DAYS_MIN = 0;
|
||||
private const USER_INACTIVITY_DAYS_MAX = 3650;
|
||||
|
||||
public static function get(string $key): ?array
|
||||
public function get(string $key): ?array
|
||||
{
|
||||
return SettingRepository::find($key);
|
||||
return $this->settingRepository->find($key);
|
||||
}
|
||||
|
||||
public static function getValue(string $key): ?string
|
||||
public function getValue(string $key): ?string
|
||||
{
|
||||
return SettingRepository::getValue($key);
|
||||
return $this->settingRepository->getValue($key);
|
||||
}
|
||||
|
||||
public static function getInt(string $key): ?int
|
||||
public function getInt(string $key): ?int
|
||||
{
|
||||
$value = SettingRepository::getValue($key);
|
||||
$value = $this->settingRepository->getValue($key);
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
public static function set(string $key, ?string $value, ?string $description = null): bool
|
||||
public function set(string $key, ?string $value, ?string $description = null): bool
|
||||
{
|
||||
return SettingRepository::set($key, $value, $description);
|
||||
return $this->settingRepository->set($key, $value, $description);
|
||||
}
|
||||
|
||||
public static function getDefaultTenantId(): ?int
|
||||
public function getDefaultTenantId(): ?int
|
||||
{
|
||||
$id = self::getInt(self::DEFAULT_TENANT_KEY);
|
||||
$id = $this->getInt(self::DEFAULT_TENANT_KEY);
|
||||
return $id && $id > 0 ? $id : null;
|
||||
}
|
||||
|
||||
public static function setDefaultTenantId(?int $tenantId, ?string $description = null): bool
|
||||
public function setDefaultTenantId(?int $tenantId, ?string $description = null): bool
|
||||
{
|
||||
$value = $tenantId && $tenantId > 0 ? (string) $tenantId : null;
|
||||
if ($value !== null) {
|
||||
$exists = TenantRepository::find($tenantId);
|
||||
$exists = $this->tenantRepository->find($tenantId);
|
||||
if (!$exists) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$desc = $description ?? 'setting.default_tenant';
|
||||
return SettingRepository::set(self::DEFAULT_TENANT_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::DEFAULT_TENANT_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getDefaultRoleId(): ?int
|
||||
public function getDefaultRoleId(): ?int
|
||||
{
|
||||
$id = self::getInt(self::DEFAULT_ROLE_KEY);
|
||||
$id = $this->getInt(self::DEFAULT_ROLE_KEY);
|
||||
return $id && $id > 0 ? $id : null;
|
||||
}
|
||||
|
||||
public static function setDefaultRoleId(?int $roleId, ?string $description = null): bool
|
||||
public function setDefaultRoleId(?int $roleId, ?string $description = null): bool
|
||||
{
|
||||
$value = $roleId && $roleId > 0 ? (string) $roleId : null;
|
||||
if ($value !== null) {
|
||||
$exists = RoleRepository::find($roleId);
|
||||
$exists = $this->roleRepository->find($roleId);
|
||||
if (!$exists) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$desc = $description ?? 'setting.default_role';
|
||||
return SettingRepository::set(self::DEFAULT_ROLE_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::DEFAULT_ROLE_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getDefaultDepartmentId(): ?int
|
||||
public function getDefaultDepartmentId(): ?int
|
||||
{
|
||||
$id = self::getInt(self::DEFAULT_DEPARTMENT_KEY);
|
||||
$id = $this->getInt(self::DEFAULT_DEPARTMENT_KEY);
|
||||
return $id && $id > 0 ? $id : null;
|
||||
}
|
||||
|
||||
public static function setDefaultDepartmentId(?int $departmentId, ?string $description = null): bool
|
||||
public function setDefaultDepartmentId(?int $departmentId, ?string $description = null): bool
|
||||
{
|
||||
$value = $departmentId && $departmentId > 0 ? (string) $departmentId : null;
|
||||
if ($value !== null) {
|
||||
$exists = DepartmentRepository::find($departmentId);
|
||||
$exists = $this->departmentRepository->find($departmentId);
|
||||
if (!$exists) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$desc = $description ?? 'setting.default_department';
|
||||
return SettingRepository::set(self::DEFAULT_DEPARTMENT_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::DEFAULT_DEPARTMENT_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getAppTitle(): ?string
|
||||
public function getAppTitle(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_TITLE_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_TITLE_KEY);
|
||||
$value = $value !== null ? trim($value) : null;
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setAppTitle(?string $title, ?string $description = null): bool
|
||||
public function setAppTitle(?string $title, ?string $description = null): bool
|
||||
{
|
||||
$value = $title !== null ? trim($title) : null;
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.app_title';
|
||||
return SettingRepository::set(self::APP_TITLE_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_TITLE_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getAppLocale(): ?string
|
||||
public function getAppLocale(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_LOCALE_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_LOCALE_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setAppLocale(?string $locale, ?string $description = null): bool
|
||||
public function setAppLocale(?string $locale, ?string $description = null): bool
|
||||
{
|
||||
$value = $locale !== null ? trim((string) $locale) : '';
|
||||
if ($value === '') {
|
||||
@@ -160,108 +168,108 @@ class SettingService
|
||||
}
|
||||
}
|
||||
$desc = $description ?? 'setting.app_locale';
|
||||
return SettingRepository::set(self::APP_LOCALE_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_LOCALE_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getAppTheme(): ?string
|
||||
public function getAppTheme(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_THEME_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_THEME_KEY);
|
||||
$value = $value !== null ? strtolower(trim((string) $value)) : '';
|
||||
if (!in_array($value, self::allowedThemes(), true)) {
|
||||
if (!in_array($value, $this->allowedThemes(), true)) {
|
||||
return null;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function setAppTheme(?string $theme, ?string $description = null): bool
|
||||
public function setAppTheme(?string $theme, ?string $description = null): bool
|
||||
{
|
||||
$value = $theme !== null ? strtolower(trim((string) $theme)) : '';
|
||||
if ($value === '' || !in_array($value, self::allowedThemes(), true)) {
|
||||
if ($value === '' || !in_array($value, $this->allowedThemes(), true)) {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.app_theme';
|
||||
return SettingRepository::set(self::APP_THEME_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_THEME_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function isUserThemeAllowed(): bool
|
||||
public function isUserThemeAllowed(): bool
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_THEME_USER_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_THEME_USER_KEY);
|
||||
if ($value === null || $value === '') {
|
||||
return true;
|
||||
}
|
||||
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
public static function setUserThemeAllowed(bool $allowed, ?string $description = null): bool
|
||||
public function setUserThemeAllowed(bool $allowed, ?string $description = null): bool
|
||||
{
|
||||
$value = $allowed ? '1' : '0';
|
||||
$desc = $description ?? 'setting.app_theme_user';
|
||||
return SettingRepository::set(self::APP_THEME_USER_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_THEME_USER_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
private static function allowedThemes(): array
|
||||
private function allowedThemes(): array
|
||||
{
|
||||
return array_keys(ThemeConfigService::all());
|
||||
return array_keys($this->themeConfigService->all());
|
||||
}
|
||||
|
||||
public static function isRegistrationEnabled(): bool
|
||||
public function isRegistrationEnabled(): bool
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_REGISTRATION_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_REGISTRATION_KEY);
|
||||
if ($value === null || $value === '') {
|
||||
return true;
|
||||
}
|
||||
return in_array(strtolower($value), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
public static function setRegistrationEnabled(bool $allowed, ?string $description = null): bool
|
||||
public function setRegistrationEnabled(bool $allowed, ?string $description = null): bool
|
||||
{
|
||||
$value = $allowed ? '1' : '0';
|
||||
$desc = $description ?? 'setting.app_registration';
|
||||
return SettingRepository::set(self::APP_REGISTRATION_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_REGISTRATION_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getApiTokenDefaultTtlDays(): int
|
||||
public function getApiTokenDefaultTtlDays(): int
|
||||
{
|
||||
$maxDays = self::getApiTokenMaxTtlDays();
|
||||
$value = self::getInt(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY);
|
||||
$maxDays = $this->getApiTokenMaxTtlDays();
|
||||
$value = $this->getInt(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY);
|
||||
if ($value !== null && $value >= self::API_TOKEN_TTL_DAYS_MIN && $value <= self::API_TOKEN_TTL_DAYS_HARD_MAX) {
|
||||
return min($value, $maxDays);
|
||||
}
|
||||
return min(self::API_TOKEN_DEFAULT_TTL_DAYS_FALLBACK, $maxDays);
|
||||
}
|
||||
|
||||
public static function setApiTokenDefaultTtlDays(?int $days, ?string $description = null): bool
|
||||
public function setApiTokenDefaultTtlDays(?int $days, ?string $description = null): bool
|
||||
{
|
||||
$value = $days ?? self::API_TOKEN_DEFAULT_TTL_DAYS_FALLBACK;
|
||||
if ($value < self::API_TOKEN_TTL_DAYS_MIN || $value > self::API_TOKEN_TTL_DAYS_HARD_MAX) {
|
||||
return false;
|
||||
}
|
||||
if ($value > self::getApiTokenMaxTtlDays()) {
|
||||
if ($value > $this->getApiTokenMaxTtlDays()) {
|
||||
return false;
|
||||
}
|
||||
$desc = $description ?? 'setting.api_token_default_ttl_days';
|
||||
return SettingRepository::set(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY, (string) $value, $desc);
|
||||
return $this->settingRepository->set(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY, (string) $value, $desc);
|
||||
}
|
||||
|
||||
public static function getApiTokenMaxTtlDays(): int
|
||||
public function getApiTokenMaxTtlDays(): int
|
||||
{
|
||||
$value = self::getInt(self::API_TOKEN_MAX_TTL_DAYS_KEY);
|
||||
$value = $this->getInt(self::API_TOKEN_MAX_TTL_DAYS_KEY);
|
||||
if ($value !== null && $value >= self::API_TOKEN_TTL_DAYS_MIN && $value <= self::API_TOKEN_TTL_DAYS_HARD_MAX) {
|
||||
return $value;
|
||||
}
|
||||
return self::API_TOKEN_MAX_TTL_DAYS_FALLBACK;
|
||||
}
|
||||
|
||||
public static function setApiTokenMaxTtlDays(?int $days, ?string $description = null): bool
|
||||
public function setApiTokenMaxTtlDays(?int $days, ?string $description = null): bool
|
||||
{
|
||||
$value = $days ?? self::API_TOKEN_MAX_TTL_DAYS_FALLBACK;
|
||||
if ($value < self::API_TOKEN_TTL_DAYS_MIN || $value > self::API_TOKEN_TTL_DAYS_HARD_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentDefault = self::getInt(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY);
|
||||
$currentDefault = $this->getInt(self::API_TOKEN_DEFAULT_TTL_DAYS_KEY);
|
||||
if ($currentDefault !== null && $currentDefault > $value) {
|
||||
$defaultUpdated = SettingRepository::set(
|
||||
$defaultUpdated = $this->settingRepository->set(
|
||||
self::API_TOKEN_DEFAULT_TTL_DAYS_KEY,
|
||||
(string) $value,
|
||||
'setting.api_token_default_ttl_days'
|
||||
@@ -272,26 +280,26 @@ class SettingService
|
||||
}
|
||||
|
||||
$desc = $description ?? 'setting.api_token_max_ttl_days';
|
||||
return SettingRepository::set(self::API_TOKEN_MAX_TTL_DAYS_KEY, (string) $value, $desc);
|
||||
return $this->settingRepository->set(self::API_TOKEN_MAX_TTL_DAYS_KEY, (string) $value, $desc);
|
||||
}
|
||||
|
||||
public static function getUserInactivityDeactivateDays(): int
|
||||
public function getUserInactivityDeactivateDays(): int
|
||||
{
|
||||
$value = self::getInt(self::USER_INACTIVITY_DEACTIVATE_DAYS_KEY);
|
||||
if ($value !== null && self::isValidInactivityDays($value)) {
|
||||
$value = $this->getInt(self::USER_INACTIVITY_DEACTIVATE_DAYS_KEY);
|
||||
if ($value !== null && $this->isValidInactivityDays($value)) {
|
||||
return $value;
|
||||
}
|
||||
return self::USER_INACTIVITY_DEACTIVATE_DAYS_FALLBACK;
|
||||
}
|
||||
|
||||
public static function setUserInactivityDeactivateDays(?int $days, ?string $description = null): bool
|
||||
public function setUserInactivityDeactivateDays(?int $days, ?string $description = null): bool
|
||||
{
|
||||
$value = $days ?? self::USER_INACTIVITY_DEACTIVATE_DAYS_FALLBACK;
|
||||
if (!self::isValidInactivityDays($value)) {
|
||||
if (!$this->isValidInactivityDays($value)) {
|
||||
return false;
|
||||
}
|
||||
if ($value === 0) {
|
||||
$deleteUpdated = SettingRepository::set(
|
||||
$deleteUpdated = $this->settingRepository->set(
|
||||
self::USER_INACTIVITY_DELETE_DAYS_KEY,
|
||||
'0',
|
||||
'setting.user_inactivity_delete_days'
|
||||
@@ -301,79 +309,79 @@ class SettingService
|
||||
}
|
||||
}
|
||||
$desc = $description ?? 'setting.user_inactivity_deactivate_days';
|
||||
return SettingRepository::set(self::USER_INACTIVITY_DEACTIVATE_DAYS_KEY, (string) $value, $desc);
|
||||
return $this->settingRepository->set(self::USER_INACTIVITY_DEACTIVATE_DAYS_KEY, (string) $value, $desc);
|
||||
}
|
||||
|
||||
public static function getUserInactivityDeleteDays(): int
|
||||
public function getUserInactivityDeleteDays(): int
|
||||
{
|
||||
$deactivateDays = self::getUserInactivityDeactivateDays();
|
||||
$deactivateDays = $this->getUserInactivityDeactivateDays();
|
||||
if ($deactivateDays <= 0) {
|
||||
return 0;
|
||||
}
|
||||
$value = self::getInt(self::USER_INACTIVITY_DELETE_DAYS_KEY);
|
||||
if ($value !== null && self::isValidInactivityDays($value)) {
|
||||
$value = $this->getInt(self::USER_INACTIVITY_DELETE_DAYS_KEY);
|
||||
if ($value !== null && $this->isValidInactivityDays($value)) {
|
||||
return $value;
|
||||
}
|
||||
return self::USER_INACTIVITY_DELETE_DAYS_FALLBACK;
|
||||
}
|
||||
|
||||
public static function setUserInactivityDeleteDays(?int $days, ?string $description = null): bool
|
||||
public function setUserInactivityDeleteDays(?int $days, ?string $description = null): bool
|
||||
{
|
||||
$value = $days ?? self::USER_INACTIVITY_DELETE_DAYS_FALLBACK;
|
||||
if (!self::isValidInactivityDays($value)) {
|
||||
if (!$this->isValidInactivityDays($value)) {
|
||||
return false;
|
||||
}
|
||||
if ($value > 0 && self::getUserInactivityDeactivateDays() <= 0) {
|
||||
if ($value > 0 && $this->getUserInactivityDeactivateDays() <= 0) {
|
||||
return false;
|
||||
}
|
||||
$desc = $description ?? 'setting.user_inactivity_delete_days';
|
||||
return SettingRepository::set(self::USER_INACTIVITY_DELETE_DAYS_KEY, (string) $value, $desc);
|
||||
return $this->settingRepository->set(self::USER_INACTIVITY_DELETE_DAYS_KEY, (string) $value, $desc);
|
||||
}
|
||||
|
||||
public static function getApiCorsAllowedOrigins(): array
|
||||
public function getApiCorsAllowedOrigins(): array
|
||||
{
|
||||
$stored = SettingRepository::getValue(self::API_CORS_ALLOWED_ORIGINS_KEY);
|
||||
$stored = $this->settingRepository->getValue(self::API_CORS_ALLOWED_ORIGINS_KEY);
|
||||
if ($stored === null || trim($stored) === '') {
|
||||
return [];
|
||||
}
|
||||
return self::parseCorsOrigins($stored, false) ?? [];
|
||||
return $this->parseCorsOrigins($stored, false) ?? [];
|
||||
}
|
||||
|
||||
public static function getApiCorsAllowedOriginsText(): string
|
||||
public function getApiCorsAllowedOriginsText(): string
|
||||
{
|
||||
$origins = self::getApiCorsAllowedOrigins();
|
||||
$origins = $this->getApiCorsAllowedOrigins();
|
||||
return implode("\n", $origins);
|
||||
}
|
||||
|
||||
public static function setApiCorsAllowedOrigins(?string $rawOrigins, ?string $description = null): bool
|
||||
public function setApiCorsAllowedOrigins(?string $rawOrigins, ?string $description = null): bool
|
||||
{
|
||||
$value = (string) ($rawOrigins ?? '');
|
||||
if (trim($value) === '') {
|
||||
return SettingRepository::set(
|
||||
return $this->settingRepository->set(
|
||||
self::API_CORS_ALLOWED_ORIGINS_KEY,
|
||||
null,
|
||||
$description ?? 'setting.api_cors_allowed_origins'
|
||||
);
|
||||
}
|
||||
|
||||
$origins = self::parseCorsOrigins($value, true);
|
||||
$origins = $this->parseCorsOrigins($value, true);
|
||||
if ($origins === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SettingRepository::set(
|
||||
return $this->settingRepository->set(
|
||||
self::API_CORS_ALLOWED_ORIGINS_KEY,
|
||||
implode("\n", $origins),
|
||||
$description ?? 'setting.api_cors_allowed_origins'
|
||||
);
|
||||
}
|
||||
|
||||
private static function parseCorsOrigins(string $rawOrigins, bool $strict): ?array
|
||||
private function parseCorsOrigins(string $rawOrigins, bool $strict): ?array
|
||||
{
|
||||
$parts = preg_split('/[\r\n,]+/', $rawOrigins) ?: [];
|
||||
$normalizedOrigins = [];
|
||||
foreach ($parts as $part) {
|
||||
$origin = self::normalizeCorsOrigin($part);
|
||||
$origin = $this->normalizeCorsOrigin($part);
|
||||
if ($origin === null) {
|
||||
if ($strict && trim((string) $part) !== '') {
|
||||
return null;
|
||||
@@ -385,7 +393,7 @@ class SettingService
|
||||
return array_keys($normalizedOrigins);
|
||||
}
|
||||
|
||||
private static function normalizeCorsOrigin(string $origin): ?string
|
||||
private function normalizeCorsOrigin(string $origin): ?string
|
||||
{
|
||||
$origin = trim($origin);
|
||||
if ($origin === '') {
|
||||
@@ -426,33 +434,33 @@ class SettingService
|
||||
return $scheme . '://' . $host . $portSuffix;
|
||||
}
|
||||
|
||||
public static function getMicrosoftSharedClientId(): ?string
|
||||
public function getMicrosoftSharedClientId(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::MICROSOFT_SHARED_CLIENT_ID_KEY);
|
||||
$value = $this->settingRepository->getValue(self::MICROSOFT_SHARED_CLIENT_ID_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setMicrosoftSharedClientId(?string $clientId, ?string $description = null): bool
|
||||
public function setMicrosoftSharedClientId(?string $clientId, ?string $description = null): bool
|
||||
{
|
||||
$value = $clientId !== null ? trim((string) $clientId) : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.microsoft_shared_client_id';
|
||||
return SettingRepository::set(self::MICROSOFT_SHARED_CLIENT_ID_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::MICROSOFT_SHARED_CLIENT_ID_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getMicrosoftSharedClientSecretEncrypted(): ?string
|
||||
public function getMicrosoftSharedClientSecretEncrypted(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::MICROSOFT_SHARED_CLIENT_SECRET_ENC_KEY);
|
||||
$value = $this->settingRepository->getValue(self::MICROSOFT_SHARED_CLIENT_SECRET_ENC_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function getMicrosoftSharedClientSecret(): ?string
|
||||
public function getMicrosoftSharedClientSecret(): ?string
|
||||
{
|
||||
$encrypted = self::getMicrosoftSharedClientSecretEncrypted();
|
||||
$encrypted = $this->getMicrosoftSharedClientSecretEncrypted();
|
||||
if ($encrypted === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -465,11 +473,11 @@ class SettingService
|
||||
return $decrypted !== '' ? $decrypted : null;
|
||||
}
|
||||
|
||||
public static function setMicrosoftSharedClientSecret(?string $secret, ?string $description = null): bool
|
||||
public function setMicrosoftSharedClientSecret(?string $secret, ?string $description = null): bool
|
||||
{
|
||||
$value = $secret !== null ? trim((string) $secret) : '';
|
||||
if ($value === '') {
|
||||
return SettingRepository::set(
|
||||
return $this->settingRepository->set(
|
||||
self::MICROSOFT_SHARED_CLIENT_SECRET_ENC_KEY,
|
||||
null,
|
||||
$description ?? 'setting.microsoft_shared_client_secret_enc'
|
||||
@@ -477,12 +485,12 @@ class SettingService
|
||||
}
|
||||
$encrypted = Crypto::encryptString($value);
|
||||
$desc = $description ?? 'setting.microsoft_shared_client_secret_enc';
|
||||
return SettingRepository::set(self::MICROSOFT_SHARED_CLIENT_SECRET_ENC_KEY, $encrypted, $desc);
|
||||
return $this->settingRepository->set(self::MICROSOFT_SHARED_CLIENT_SECRET_ENC_KEY, $encrypted, $desc);
|
||||
}
|
||||
|
||||
public static function getMicrosoftAuthority(): string
|
||||
public function getMicrosoftAuthority(): string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::MICROSOFT_AUTHORITY_KEY);
|
||||
$value = $this->settingRepository->getValue(self::MICROSOFT_AUTHORITY_KEY);
|
||||
$value = trim((string) ($value ?? ''));
|
||||
if ($value === '') {
|
||||
return 'https://login.microsoftonline.com/common/v2.0';
|
||||
@@ -490,7 +498,7 @@ class SettingService
|
||||
return rtrim($value, '/');
|
||||
}
|
||||
|
||||
public static function setMicrosoftAuthority(?string $authority, ?string $description = null): bool
|
||||
public function setMicrosoftAuthority(?string $authority, ?string $description = null): bool
|
||||
{
|
||||
$value = trim((string) ($authority ?? ''));
|
||||
if ($value === '') {
|
||||
@@ -500,12 +508,12 @@ class SettingService
|
||||
return false;
|
||||
}
|
||||
$desc = $description ?? 'setting.microsoft_authority';
|
||||
return SettingRepository::set(self::MICROSOFT_AUTHORITY_KEY, rtrim($value, '/'), $desc);
|
||||
return $this->settingRepository->set(self::MICROSOFT_AUTHORITY_KEY, rtrim($value, '/'), $desc);
|
||||
}
|
||||
|
||||
public static function getAppPrimaryColor(): ?string
|
||||
public function getAppPrimaryColor(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::APP_PRIMARY_COLOR_KEY);
|
||||
$value = $this->settingRepository->getValue(self::APP_PRIMARY_COLOR_KEY);
|
||||
$value = $value !== null ? strtolower(trim((string) $value)) : '';
|
||||
if ($value === '') {
|
||||
return null;
|
||||
@@ -516,7 +524,7 @@ class SettingService
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function setAppPrimaryColor(?string $color, ?string $description = null): bool
|
||||
public function setAppPrimaryColor(?string $color, ?string $description = null): bool
|
||||
{
|
||||
$value = $color !== null ? strtolower(trim((string) $color)) : '';
|
||||
if ($value !== '' && $value[0] !== '#') {
|
||||
@@ -533,29 +541,29 @@ class SettingService
|
||||
return false;
|
||||
}
|
||||
$desc = $description ?? 'setting.app_primary_color';
|
||||
return SettingRepository::set(self::APP_PRIMARY_COLOR_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::APP_PRIMARY_COLOR_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpHost(): ?string
|
||||
public function getSmtpHost(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_HOST_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_HOST_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setSmtpHost(?string $host, ?string $description = null): bool
|
||||
public function setSmtpHost(?string $host, ?string $description = null): bool
|
||||
{
|
||||
$value = $host !== null ? trim((string) $host) : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_host';
|
||||
return SettingRepository::set(self::SMTP_HOST_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_HOST_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpPort(): ?int
|
||||
public function getSmtpPort(): ?int
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_PORT_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_PORT_KEY);
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -563,50 +571,50 @@ class SettingService
|
||||
return $port > 0 ? $port : null;
|
||||
}
|
||||
|
||||
public static function setSmtpPort(?int $port, ?string $description = null): bool
|
||||
public function setSmtpPort(?int $port, ?string $description = null): bool
|
||||
{
|
||||
$value = $port && $port > 0 ? (string) $port : null;
|
||||
$desc = $description ?? 'setting.smtp_port';
|
||||
return SettingRepository::set(self::SMTP_PORT_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_PORT_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpUser(): ?string
|
||||
public function getSmtpUser(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_USER_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_USER_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setSmtpUser(?string $user, ?string $description = null): bool
|
||||
public function setSmtpUser(?string $user, ?string $description = null): bool
|
||||
{
|
||||
$value = $user !== null ? trim((string) $user) : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_user';
|
||||
return SettingRepository::set(self::SMTP_USER_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_USER_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpPassword(): ?string
|
||||
public function getSmtpPassword(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_PASSWORD_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_PASSWORD_KEY);
|
||||
$value = $value !== null ? (string) $value : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setSmtpPassword(?string $password, ?string $description = null): bool
|
||||
public function setSmtpPassword(?string $password, ?string $description = null): bool
|
||||
{
|
||||
$value = $password !== null ? (string) $password : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_password';
|
||||
return SettingRepository::set(self::SMTP_PASSWORD_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_PASSWORD_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpSecure(): ?string
|
||||
public function getSmtpSecure(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_SECURE_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_SECURE_KEY);
|
||||
$value = $value !== null ? strtolower(trim((string) $value)) : '';
|
||||
if (!in_array($value, ['tls', 'ssl', 'none'], true)) {
|
||||
return null;
|
||||
@@ -614,7 +622,7 @@ class SettingService
|
||||
return $value === 'none' ? null : $value;
|
||||
}
|
||||
|
||||
public static function setSmtpSecure(?string $secure, ?string $description = null): bool
|
||||
public function setSmtpSecure(?string $secure, ?string $description = null): bool
|
||||
{
|
||||
$value = $secure !== null ? strtolower(trim((string) $secure)) : '';
|
||||
if ($value === '' || $value === 'none') {
|
||||
@@ -623,44 +631,44 @@ class SettingService
|
||||
return false;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_secure';
|
||||
return SettingRepository::set(self::SMTP_SECURE_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_SECURE_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpFrom(): ?string
|
||||
public function getSmtpFrom(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_FROM_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_FROM_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setSmtpFrom(?string $from, ?string $description = null): bool
|
||||
public function setSmtpFrom(?string $from, ?string $description = null): bool
|
||||
{
|
||||
$value = $from !== null ? trim((string) $from) : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_from';
|
||||
return SettingRepository::set(self::SMTP_FROM_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_FROM_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public static function getSmtpFromName(): ?string
|
||||
public function getSmtpFromName(): ?string
|
||||
{
|
||||
$value = SettingRepository::getValue(self::SMTP_FROM_NAME_KEY);
|
||||
$value = $this->settingRepository->getValue(self::SMTP_FROM_NAME_KEY);
|
||||
$value = $value !== null ? trim((string) $value) : '';
|
||||
return $value !== '' ? $value : null;
|
||||
}
|
||||
|
||||
public static function setSmtpFromName(?string $fromName, ?string $description = null): bool
|
||||
public function setSmtpFromName(?string $fromName, ?string $description = null): bool
|
||||
{
|
||||
$value = $fromName !== null ? trim((string) $fromName) : '';
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$desc = $description ?? 'setting.smtp_from_name';
|
||||
return SettingRepository::set(self::SMTP_FROM_NAME_KEY, $value, $desc);
|
||||
return $this->settingRepository->set(self::SMTP_FROM_NAME_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
private static function isValidInactivityDays(int $days): bool
|
||||
private function isValidInactivityDays(int $days): bool
|
||||
{
|
||||
return $days >= self::USER_INACTIVITY_DAYS_MIN && $days <= self::USER_INACTIVITY_DAYS_MAX;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user