-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDatabase.php
More file actions
58 lines (47 loc) · 1.4 KB
/
Copy pathDatabase.php
File metadata and controls
58 lines (47 loc) · 1.4 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/* Originally from Icinga Web 2 X.509 Module | (c) 2022 Icinga GmbH | GPLv2+ */
/* generated by icingaweb2-module-scaffoldbuilder | GPLv2+ */
namespace Icinga\Module\Oidc\Common;
use Icinga\Application\Config;
use Icinga\Data\ResourceFactory;
use ipl\Sql;
use Pdo\Mysql;
use PDO;
final class Database
{
/** @var Sql\Connection Database connection */
private static $instance;
private function __construct()
{
}
/**
* Get the database connection
*
* @return Sql\Connection
*/
public static function get(): Sql\Connection
{
if (self::$instance === null) {
self::$instance = self::getDb();
}
return self::$instance;
}
/**
* Get the connection to the X.509 database
*
* @return Sql\Connection
*/
private static function getDb(): Sql\Connection
{
$config = new Sql\Config(ResourceFactory::getResourceConfig(
Config::module('oidc')->get('backend', 'resource', 'oidc')
));
$options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
if ($config->db === 'mysql') {
$options[Mysql::ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE"
. ",NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
}
$config->options = $options;
return new Sql\Connection($config);
}
}