Files
DesignPatternsPHP/Structural/DependencyInjection/DatabaseConnection.php
Dominik Liebler 4678b5d86f PHP8
2021-04-12 14:04:45 +02:00

26 lines
699 B
PHP

<?php declare(strict_types=1);
namespace DesignPatterns\Structural\DependencyInjection;
class DatabaseConnection
{
public function __construct(private DatabaseConfiguration $configuration)
{
}
public function getDsn(): string
{
// this is just for the sake of demonstration, not a real DSN
// notice that only the injected config is used here, so there is
// a real separation of concerns here
return sprintf(
'%s:%s@%s:%d',
$this->configuration->getUsername(),
$this->configuration->getPassword(),
$this->configuration->getHost(),
$this->configuration->getPort()
);
}
}