Passed
Push — master ( e5e54a...8779b5 )
by Wilmer
10:52
created

Dsn::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
final class Dsn
8
{
9
    private string $database;
10
    private string $driver;
11
    private string $server;
12
    private string $port;
13
14
    public function __construct(string $driver, string $server, string $database, string $port = '1433')
15
    {
16
        $this->driver = $driver;
17
        $this->server = $server;
18
        $this->database = $database;
19
        $this->port = $port;
20
    }
21
22
    /**
23
     * @return string the Data Source Name, or DSN, contains the information required to connect to the database.
24
     * Please refer to the [PHP manual](http://php.net/manual/en/pdo.construct.php) on the format of the DSN string.
25
     *
26
     * The `driver` array key is used as the driver prefix of the DSN, all further key-value pairs are rendered as
27
     * `key=value` and concatenated by `;`. For example:
28
     *
29
     * ```php
30
     * $dsn = new MssqlDsn('sqlsrv', 'localhost', 'yiitest', '1433');
31
     * $connection = new MssqlConnection($this->cache, $this->logger, $this->profiler, $dsn->getDsn());
32
     * ```
33
     *
34
     * Will result in the DSN string `sqlsrv:Server=localhost,1433;Database=yiitest`.
35
     */
36
37
    public function getDsn(): string
38
    {
39
        return "$this->driver:" . "Server=$this->server," . "$this->port;" . "Database=$this->database";
40
    }
41
42
    public function getDriver(): string
43
    {
44
        return $this->driver;
45
    }
46
}
47