Skip to content

Commit

Permalink
Starting to cleanup code so that it conforms to what documentation says
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 29, 2014
1 parent dac8362 commit ca886ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
26 changes: 10 additions & 16 deletions src/Core/StaticConfigTrait.php
Expand Up @@ -79,18 +79,19 @@ public static function config($key, $config = null) {
}
return;
}

if (isset(static::$_config[$key])) {
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key "%s"', $key));
}
if (is_array($config)) {
$config = static::parseDsn($config);
} elseif ($config === null && is_array($key)) {
foreach ($key as $name => $settings) {
$key[$name] = static::parseDsn($settings);
}
} elseif (is_object($config)) {

if (is_array($config) && isset($config['url'])) {
$config = static::parseDsn($config['url']);
}

if (is_object($config)) {
$config = ['className' => $config];
}

if (isset($config['engine']) && empty($config['className'])) {
$config['className'] = $config['engine'];
unset($config['engine']);
Expand Down Expand Up @@ -165,17 +166,10 @@ public static function configured() {
*
* Note that querystring arguments are also parsed and set as values in the returned configuration.
*
* @param array $config An array with a `url` key mapping to a string DSN
* @param string $dsn The DSN string to convert to a configuration array
* @return mixed null when adding configuration and an array of configuration data when reading.
*/
public static function parseDsn($config = null) {
if (!is_array($config) || !isset($config['url'])) {
return $config;
}

$driver = null;
$dsn = $config['url'];

public static function parseDsn($dsn) {
if (preg_match("/^([\w\\\]+)/", $dsn, $matches)) {
$scheme = $matches[1];
$dsn = preg_replace("/^([\w\\\]+)/", 'file', $dsn);
Expand Down
9 changes: 1 addition & 8 deletions tests/bootstrap.php
Expand Up @@ -101,14 +101,7 @@
putenv('db_dsn=sqlite:///memory:');
}

ConnectionManager::config('test', [
'driver' => getenv('db_class'),
'url' => getenv('db_dsn'),
'database' => getenv('db_database'),
'username' => getenv('db_login'),
'password' => getenv('db_password'),
'timezone' => 'UTC'
]);
ConnectionManager::config('test', ['url' => getenv('db_dsn')]);

Configure::write('Session', [
'defaults' => 'php'
Expand Down

0 comments on commit ca886ad

Please sign in to comment.