cycle /
database
| 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\MySQL; |
||
| 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
Loading history...
|
|||
| 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 | * @param non-empty-string|null $user |
||
| 31 | * @param non-empty-string|null $password |
||
| 32 | */ |
||
| 33 | public function __construct( |
||
| 34 | string|\Stringable $dsn, |
||
| 35 | ?string $user = null, |
||
| 36 | ?string $password = null, |
||
| 37 | array $options = [], |
||
| 38 | ) { |
||
| 39 | parent::__construct($user, $password, $options); |
||
| 40 | |||
| 41 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
| 42 | $this->dsn = DataSourceName::normalize((string) $dsn, $this->getName()); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getSourceString(): string |
||
| 46 | { |
||
| 47 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
| 48 | return $this->database ??= DataSourceName::read($this->getDsn(), 'dbname') ?? '*'; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function getDsn(): string |
||
| 52 | { |
||
| 53 | return $this->dsn; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |