Browse Source

Merge pull request #5102 from cakephp/3.0-fix-exception

Actually showing exception for warning users about username
Mark Story 11 years ago
parent
commit
c1d7a07def
2 changed files with 7 additions and 7 deletions
  1. 7 0
      src/Database/Driver.php
  2. 0 7
      src/Database/Driver/PDODriverTrait.php

+ 7 - 0
src/Database/Driver.php

@@ -17,6 +17,7 @@ namespace Cake\Database;
 use Cake\Database\Query;
 use Cake\Database\QueryCompiler;
 use Cake\Database\ValueBinder;
+use InvalidArgumentException;
 
 /**
  * Represents a database diver containing all specificities for
@@ -52,8 +53,14 @@ abstract class Driver {
  * Constructor
  *
  * @param array $config The configuration for the driver.
+ * @throws InvalidArgumentException
  */
 	public function __construct($config = []) {
+		if (empty($config['username']) && !empty($config['login'])) {
+			throw new InvalidArgumentException(
+				'Please pass "username" instead of "login" for connecting to the database'
+			);
+		}
 		$config += $this->_baseConfig;
 		$this->_config = $config;
 		if (!empty($config['quoteIdentifiers'])) {

+ 0 - 7
src/Database/Driver/PDODriverTrait.php

@@ -15,7 +15,6 @@
 namespace Cake\Database\Driver;
 
 use Cake\Database\Statement\PDOStatement;
-use InvalidArgumentException;
 use PDO;
 
 /**
@@ -36,14 +35,8 @@ trait PDODriverTrait {
  * @param string $dsn A Driver-specific PDO-DSN
  * @param array $config configuration to be used for creating connection
  * @return bool true on success
- * @throws InvalidArgumentException
  */
 	protected function _connect($dsn, array $config) {
-		if (empty($config['username']) && !empty($config['login'])) {
-			throw new InvalidArgumentException(
-				'Please pass "username" instead of "login" for connecting to the database'
-			);
-		}
 		$connection = new PDO(
 			$dsn,
 			$config['username'],