-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix when using enviroment variables and dsn (#43)
* Do not resolve arguments on build * Bugfix * cs
- Loading branch information
Showing
4 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace BM\BackupManagerBundle\Factory; | ||
|
||
use BackupManager\Config\Config; | ||
use Nyholm\DSN; | ||
|
||
/** | ||
* A factory class to resolve DSN | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class ConfigFactory | ||
{ | ||
/** | ||
* If a DSN is configured, then let it override other database storages. | ||
* @param array $config | ||
* @return Config | ||
*/ | ||
public static function createConfig(array $config) | ||
{ | ||
foreach ($config as $key => $databaseConfig) { | ||
if (isset($databaseConfig['dsn'])) { | ||
$dsn = new DSN($databaseConfig['dsn']); | ||
$config[$key]['type'] = $dsn->getProtocol(); | ||
$config[$key]['host'] = $dsn->getFirstHost(); | ||
$config[$key]['port'] = $dsn->getFirstPort(); | ||
$config[$key]['user'] = $dsn->getUsername(); | ||
$config[$key]['pass'] = $dsn->getPassword(); | ||
$config[$key]['database'] = $dsn->getDatabase(); | ||
unset($config[$key]['dsn']); | ||
} | ||
} | ||
|
||
return new Config($config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters