Repository navigation
Expand file tree
/
Copy pathConfiguration.php
More file actions
91 lines (73 loc) · 1.61 KB
/
Copy pathConfiguration.php
File metadata and controls
91 lines (73 loc) · 1.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace SOB;
class Configuration
{
/**
* @param array<string,string|int> $config
*/
public function __construct(private array $config, private int $iterations)
{
}
public function getDatabase() : string
{
if (! empty($this->config['dbname']))
{
return $this->config['dbname'];
}
$database = \strtolower($this->getNamespace());
if ('sqlite' == $this->getDriver())
{
$database .= '.sqlite';
}
return $database;
}
public function getDescription() : string
{
return $this->config['description'] ?? $this->getPDOConnectionString();
}
public function getDriver() : string
{
return $this->config['driver'] ?? 'sqlite';
}
public function getHost() : string
{
return $this->config['host'] ?? 'localhost';
}
public function getIterations() : int
{
return $this->iterations;
}
public function getNamespace() : string
{
return $this->config['namespace'] ?? 'PHPFUI';
}
public function getPassword() : string
{
return $this->config['password'] ?? '';
}
public function getPDOConnectionString() : string
{
$driver = $this->getDriver();
if ('sqlite' == $driver)
{
$driver .= ':' . $this->getDatabase();
}
else
{
$driver .= ':host=' . $this->getHost() . ';dbname=' . $this->getDatabase() . ';port=' . $this->getPort();
}
if ('pgsql' == $driver)
{
$driver .= ':user=' . $this->getUser() . ';password=' . $this->getPassword();
}
return $driver;
}
public function getPort() : int
{
return $this->config['port'] ?? 3306;
}
public function getUser() : string
{
return $this->config['user'] ?? 'root';
}
}