PdoConfig::getPass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\ReadModel\Storage\Pdo;
12
13
use Borobudur\Cqrs\ReadModel\Storage\Pdo\Parser\ParserInterface;
14
use Borobudur\Cqrs\ReadModel\Storage\Pdo\Parser\DefaultParser;
15
use Borobudur\Cqrs\ReadModel\Storage\Pdo\Parser\PostgresParser;
16
17
/**
18
 * @author      Iqbal Maulana <[email protected]>
19
 * @created     8/18/15
20
 */
21
class PdoConfig
22
{
23
    /**
24
     * @var string
25
     */
26
    private $dsn;
27
28
    /**
29
     * @var string
30
     */
31
    private $engine;
32
33
    /**
34
     * @var string
35
     */
36
    private $host;
37
38
    /**
39
     * @var int
40
     */
41
    private $port;
42
43
    /**
44
     * @var string
45
     */
46
    private $database;
47
48
    /**
49
     * @var string
50
     */
51
    private $user;
52
53
    /**
54
     * @var string
55
     */
56
    private $pass;
57
58
    /**
59
     * @var ParserInterface
60
     */
61
    private $parser;
62
63
    /**
64
     * Constructor.
65
     *
66
     * @param string      $engine
67
     * @param string      $host
68
     * @param int         $port
69
     * @param string      $database
70
     * @param string|null $user
71
     * @param string|null $pass
72
     */
73
    public function __construct($engine, $host, $port, $database, $user = null, $pass = null)
74
    {
75
        $this->dsn = sprintf('%s:dbname=%s;host=%s;port=%d', $engine, $database, $host, $port);
76
        $this->engine = $engine;
77
        $this->host = $host;
78
        $this->port = $port;
79
        $this->database = $database;
80
        $this->user = $user;
81
        $this->pass = $pass;
82
        $this->parser = $this->createParser();
83
    }
84
85
    /**
86
     * Get dsn.
87
     *
88
     * @return string
89
     */
90
    public function getDsn()
91
    {
92
        return $this->dsn;
93
    }
94
95
    /**
96
     * Get engine.
97
     *
98
     * @return string
99
     */
100
    public function getEngine()
101
    {
102
        return $this->engine;
103
    }
104
105
    /**
106
     * Get host.
107
     *
108
     * @return string
109
     */
110
    public function getHost()
111
    {
112
        return $this->host;
113
    }
114
115
    /**
116
     * Get port.
117
     *
118
     * @return int
119
     */
120
    public function getPort()
121
    {
122
        return $this->port;
123
    }
124
125
    /**
126
     * Get database.
127
     *
128
     * @return string
129
     */
130
    public function getDatabase()
131
    {
132
        return $this->database;
133
    }
134
135
    /**
136
     * Get user.
137
     *
138
     * @return string|string
139
     */
140
    public function getUser()
141
    {
142
        return $this->user;
143
    }
144
145
    /**
146
     * Get pass.
147
     *
148
     * @return string|null
149
     */
150
    public function getPass()
151
    {
152
        return $this->pass;
153
    }
154
155
    /**
156
     * Get parser.
157
     *
158
     * @return ParserInterface
159
     */
160
    public function getParser()
161
    {
162
        return $this->parser;
163
    }
164
165
    /**
166
     * @return ParserInterface
167
     */
168
    protected function createParser()
169
    {
170
        switch(strtolower($this->engine)) {
171
            case 'pgsql':
172
                return new PostgresParser();
173
        }
174
175
        return new DefaultParser();
176
    }
177
}
178