Browse Source

Starting to cleanup code so that it conforms to what documentation says

Jose Lorenzo Rodriguez 11 years ago
parent
commit
ca886ad426
2 changed files with 11 additions and 24 deletions
  1. 10 16
      src/Core/StaticConfigTrait.php
  2. 1 8
      tests/bootstrap.php

+ 10 - 16
src/Core/StaticConfigTrait.php

@@ -79,18 +79,19 @@ trait StaticConfigTrait {
 			}
 			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']);
@@ -165,17 +166,10 @@ trait StaticConfigTrait {
  *
  * 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);

+ 1 - 8
tests/bootstrap.php

@@ -101,14 +101,7 @@ if (!getenv('db_dsn')) {
 	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'