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\SQLite; |
||
13 | |||
14 | use Cycle\Database\Config\ProvidesSourceString; |
||
15 | use Cycle\Database\Config\Support\DataSourceName; |
||
16 | |||
17 | class DsnConnectionConfig extends ConnectionConfig implements ProvidesSourceString |
||
18 | { |
||
19 | /** |
||
20 | * @var non-empty-string |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
21 | * |
||
22 | * @psalm-allow-private-mutation |
||
23 | */ |
||
24 | public string $dsn; |
||
25 | |||
26 | private ?string $database = null; |
||
27 | |||
28 | /** |
||
29 | * @param non-empty-string|\Stringable $dsn |
||
0 ignored issues
–
show
|
|||
30 | */ |
||
31 | public function __construct( |
||
32 | string|\Stringable $dsn, |
||
33 | array $options = [], |
||
34 | ) { |
||
35 | parent::__construct($options); |
||
36 | |||
37 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
38 | $this->dsn = DataSourceName::normalize((string) $dsn, $this->getName()); |
||
39 | } |
||
40 | |||
41 | public function getSourceString(): string |
||
42 | { |
||
43 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
44 | return $this->database ??= \substr($this->getDsn(), \strlen($this->getName()) + 1); |
||
45 | } |
||
46 | |||
47 | public function getDsn(): string |
||
48 | { |
||
49 | return $this->dsn; |
||
50 | } |
||
51 | } |
||
52 |