-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbConfig.php
44 lines (40 loc) · 1.25 KB
/
DbConfig.php
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
<?php
namespace Config;
use Yiisoft\Cache\ArrayCache;
use Yiisoft\Db\Cache\SchemaCache;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Driver;
class DbConfig
{
public static Connection $connection;
public static Driver $driver;
public function __construct(
private string $host = 'localhost',
private int $port = 5432,
private string $username = 'postgres',
private string $password = '',
private string $dbname = '',
private array $attributes = [],
private ?SchemaCache $schemaCache = null,
)
{
self::$driver = new Driver(
dsn: 'pgsql:' .
'host=' . $this->host . ';' .
'port=' . $this->port . ';' .
'dbname=' . $this->dbname . ';',
username: $this->username,
password: $this->password,
attributes: $this->attributes);
$arrayCache = new ArrayCache();
if (is_null($this->schemaCache)) {
$this->schemaCache = new SchemaCache(
psrCache: $arrayCache
);
}
self::$connection = new Connection(
driver: self::$driver,
schemaCache: $this->schemaCache,
);
}
}