mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-09 17:36:22 +02:00
28 lines
700 B
PHP
28 lines
700 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()
|
|
);
|
|
}
|
|
}
|