Skip to content

Commit

Permalink
Added ConfigHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
szeber committed May 22, 2016
1 parent 735c994 commit 4f1a7b2
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace ShoppinPal\YapepCommon\Helper;

use YapepBase\Config;

class ConfigHelper
{

/**
* Temporary helper method for creating database config from an URL in an environment variable.
*
* @param string $variableName Name of the environment variable to parse.
* @param string $connectionName Name of the connection to create.
*
* @return void
*
* @todo this in a nicer way in yapep 1.0
*/
public static function setupMySqlDbConfig($variableName, $connectionName)
{
$parsed = parse_url(getenv($variableName));

$config = Config::getInstance();

$config->set(
[
'resource.database.' . $connectionName . '.rw.backendType' => 'mysql',
'resource.database.' . $connectionName . '.rw.host' => $parsed['host'],
'resource.database.' . $connectionName . '.rw.user' => $parsed['user'],
'resource.database.' . $connectionName . '.rw.password' => $parsed['pass'],
'resource.database.' . $connectionName . '.rw.database' => ltrim($parsed['path'], '/'),
'resource.database.' . $connectionName . '.rw.port' => $parsed['port'],
'resource.database.' . $connectionName . '.rw.charset' => 'utf8',

'resource.database.' . $connectionName . '.ro.backendType' => 'mysql',
'resource.database.' . $connectionName . '.ro.host' => $parsed['host'],
'resource.database.' . $connectionName . '.ro.user' => $parsed['user'],
'resource.database.' . $connectionName . '.ro.password' => $parsed['pass'],
'resource.database.' . $connectionName . '.ro.database' => ltrim($parsed['path'], '/'),
'resource.database.' . $connectionName . '.ro.port' => $parsed['port'],
'resource.database.' . $connectionName . '.ro.charset' => 'utf8',
]
);
}


}

0 comments on commit 4f1a7b2

Please sign in to comment.