1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of Cycle Database package. |
||
5 | * |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | */ |
||
9 | |||
10 | declare(strict_types=1); |
||
11 | |||
12 | namespace Cycle\Database\Config; |
||
13 | |||
14 | abstract class ConnectionConfig |
||
15 | { |
||
16 | use RestoreStateTrait; |
||
17 | |||
18 | /** |
||
19 | * @var array<non-empty-string> |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
20 | */ |
||
21 | protected array $nonPrintableOptions = [ |
||
22 | // Postgres and MySQL |
||
23 | 'password', |
||
24 | // IBM, ODBC and DB2 |
||
25 | 'PWD', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @param non-empty-string|null $user |
||
0 ignored issues
–
show
|
|||
30 | 60 | * @param non-empty-string|null $password |
|
31 | */ |
||
32 | public function __construct( |
||
33 | public ?string $user = null, |
||
34 | 60 | public ?string $password = null, |
|
35 | ) {} |
||
36 | |||
37 | /** |
||
38 | * @return non-empty-string|null |
||
0 ignored issues
–
show
|
|||
39 | 62 | */ |
|
40 | public function getUsername(): ?string |
||
41 | 62 | { |
|
42 | return $this->user; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return non-empty-string|null |
||
0 ignored issues
–
show
|
|||
47 | 62 | */ |
|
48 | public function getPassword(): ?string |
||
49 | 62 | { |
|
50 | return $this->password; |
||
51 | } |
||
52 | |||
53 | public function __debugInfo(): array |
||
54 | { |
||
55 | return $this->toArray(); |
||
56 | } |
||
57 | |||
58 | protected function toArray(bool $secure = true): array |
||
59 | { |
||
60 | $options = \get_object_vars($this); |
||
61 | |||
62 | foreach ($options as $key => $value) { |
||
63 | if ($secure && \in_array($key, $this->nonPrintableOptions, true)) { |
||
64 | $value = '<hidden>'; |
||
65 | } |
||
66 | |||
67 | $options[$key] = $value; |
||
68 | } |
||
69 | |||
70 | return $options; |
||
71 | } |
||
72 | } |
||
73 |