@@ -107,17 +107,22 @@ final class Config
107107 /**
108108 * @param string $host
109109 * @param int $port
110- * @param string $vhost
111110 * @param string $user
112111 * @param string $pass
112+ * @param string $vhost
113113 */
114- public function __construct (string $ host , int $ port , string $ vhost = null , string $ user = null , string $ pass = null )
115- {
114+ public function __construct (
115+ string $ host = self ::DEFAULT_HOST ,
116+ int $ port = self ::DEFAULT_PORT ,
117+ string $ user = self ::DEFAULT_USER ,
118+ string $ pass = self ::DEFAULT_PASS ,
119+ string $ vhost = null
120+ ) {
116121 $ this ->host = $ host ;
117122 $ this ->port = $ port ;
123+ $ this ->user = $ user ;
124+ $ this ->pass = $ pass ;
118125 $ this ->vhost = $ vhost ?: self ::DEFAULT_VHOST ;
119- $ this ->user = $ user ?: self ::DEFAULT_USER ;
120- $ this ->pass = $ pass ?: self ::DEFAULT_PASS ;
121126 }
122127
123128 /**
@@ -133,12 +138,16 @@ public static function parse(string $dsn): self
133138
134139 $ options = \array_replace (self ::OPTIONS , $ query );
135140
141+ if (!empty ($ parts ['path ' ])) {
142+ $ parts ['path ' ] = \substr ($ parts ['path ' ], 1 );
143+ }
144+
136145 $ self = new self (
137146 $ parts ['host ' ] ?? self ::DEFAULT_HOST ,
138147 $ parts ['port ' ] ?? self ::DEFAULT_PORT ,
139- $ parts ['path ' ] ?? self ::DEFAULT_VHOST ,
140148 $ parts ['user ' ] ?? self ::DEFAULT_USER ,
141- $ parts ['pass ' ] ?? self ::DEFAULT_PASS
149+ $ parts ['pass ' ] ?? self ::DEFAULT_PASS ,
150+ $ parts ['path ' ] ?? self ::DEFAULT_VHOST
142151 );
143152
144153 $ self ->timeout = \filter_var ($ options ['timeout ' ], FILTER_VALIDATE_INT );
@@ -182,33 +191,27 @@ public function port(): int
182191 }
183192
184193 /**
185- * @param string|null $value
186- *
187194 * @return string
188195 */
189- public function user ( string $ value = null ): string
196+ public function vhost ( ): string
190197 {
191- return \is_null ( $ value ) ? $ this ->user : $ this -> user = $ value ;
198+ return $ this ->vhost ;
192199 }
193200
194201 /**
195- * @param string|null $value
196- *
197202 * @return string
198203 */
199- public function password ( string $ value = null ): string
204+ public function user ( ): string
200205 {
201- return \is_null ( $ value ) ? $ this ->pass : $ this -> pass = $ value ;
206+ return $ this ->user ;
202207 }
203208
204209 /**
205- * @param string|null $value
206- *
207210 * @return string
208211 */
209- public function vhost ( string $ value = null ): string
212+ public function password ( ): string
210213 {
211- return \is_null ( $ value ) ? $ this ->vhost : $ this -> vhost = $ value ;
214+ return $ this ->pass ;
212215 }
213216
214217 /**
0 commit comments