-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigService.php
More file actions
40 lines (34 loc) · 1.08 KB
/
ConfigService.php
File metadata and controls
40 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace OpenCoreEMR\ModuleConfig;
use OpenEMR\Common\Crypto\CryptoGen;
use OpenEMR\Common\Database\QueryUtils;
/**
* Persist module settings to the OpenEMR globals table via upsert.
*
* @author Michael A. Smith <michael@opencoreemr.com>
* @copyright Copyright (c) 2026 OpenCoreEMR Inc. <https://www.opencoreemr.com>
*/
class ConfigService
{
private const UPSERT_SQL = <<<'SQL'
INSERT INTO `globals` (`gl_name`, `gl_index`, `gl_value`)
VALUES (?, 0, ?)
ON DUPLICATE KEY UPDATE `gl_value` = ?
SQL;
/**
* Save a setting to the globals table (plaintext).
*/
public function saveSetting(string $key, string $value): void
{
QueryUtils::sqlStatementThrowException(self::UPSERT_SQL, [$key, $value, $value]);
}
/**
* Encrypt a value with CryptoGen and save it to the globals table.
*/
public function saveEncryptedSetting(string $key, string $value): void
{
$encrypted = (new CryptoGen())->encryptStandard($value);
$this->saveSetting($key, $encrypted);
}
}