1
0
Files
breadcrumb-the-shire/lib/Repository/Settings/SettingRepository.php
fs f4ce9f3378 docs: add class docblocks, business-rule comments, and transaction wrapper
- Add single-line class docblocks to all 59 repository classes and interfaces
  describing scope and responsibility
- Add multi-line docblocks to key services documenting business rules:
  AuthService (6-step login cascade), ImportService (3-phase CSV workflow),
  TenantScopeService (strict/permissive modes), PermissionService (RBAC
  resolution + two-tier caching), UserAccountService (atomicity + audit)
- Add transaction(callable) wrapper to DatabaseSessionRepository to DRY up
  begin/commit/rollback boilerplate

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 21:58:51 +01:00

37 lines
1.1 KiB
PHP

<?php
namespace MintyPHP\Repository\Settings;
use MintyPHP\DB;
/** Reads and upserts application settings as key-value pairs in the database. */
class SettingRepository implements SettingRepositoryInterface
{
public function find(string $key): ?array
{
$row = DB::selectOne('select `key`, `value`, `description`, `updated_at` from settings where `key` = ? limit 1', $key);
if (!$row) {
return null;
}
return $row['settings'] ?? $row;
}
public function getValue(string $key): ?string
{
$row = $this->find($key);
if (!$row) {
return null;
}
return array_key_exists('value', $row) ? (string) $row['value'] : null;
}
public function set(string $key, ?string $value, ?string $description = null): bool
{
$query = 'insert into settings (`key`, `value`, `description`) values (?, ?, ?) '
. 'on duplicate key update `value` = values(`value`), '
. '`description` = ifnull(values(`description`), `description`)';
$result = DB::update($query, $key, $value, $description);
return $result !== false;
}
}