[2.0] DDC-92 - Removed DoctrineException from Doctrine\DBAL\DriverManager and replaced with more specific DBALException's
This commit is contained in:
parent
03132fedfd
commit
bbce4a407a
@ -11,6 +11,28 @@ class DBALException extends \Exception
|
|||||||
|
|
||||||
public static function invalidPlatformSpecified()
|
public static function invalidPlatformSpecified()
|
||||||
{
|
{
|
||||||
return new self("Invalid 'platform' option specified, need to give an instance of \Doctrine\DBAL\Platforms\AbstractPlatform.");
|
return new self(
|
||||||
|
"Invalid 'platform' option specified, need to give an instance of ".
|
||||||
|
"\Doctrine\DBAL\Platforms\AbstractPlatform.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function invalidPdoInstance()
|
||||||
|
{
|
||||||
|
return new self(
|
||||||
|
"The 'pdo' option was used in DriverManager::getConnection() but no ".
|
||||||
|
"instance of PDO was given."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function driverRequired()
|
||||||
|
{
|
||||||
|
return new self("The options 'driver' or 'driverClass' are mandatory if no PDO ".
|
||||||
|
"instance is given to DriverManager::getConnection().");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function unknownDriver($unknownDriverName, array $knownDrivers)
|
||||||
|
{
|
||||||
|
return new self("The given 'driver' ".$unknownDriverName." is unknown, ".
|
||||||
|
"Doctrine currently supports only the following drivers: ".implode(", ", $knownDrivers));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,10 +48,7 @@ final class DriverManager
|
|||||||
);
|
);
|
||||||
|
|
||||||
/** Private constructor. This class cannot be instantiated. */
|
/** Private constructor. This class cannot be instantiated. */
|
||||||
public function __construct()
|
private function __construct() { }
|
||||||
{
|
|
||||||
throw \Doctrine\Common\DoctrineException::driverManagerCannotBeInstantiated();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection object based on the specified parameters.
|
* Creates a connection object based on the specified parameters.
|
||||||
@ -110,7 +107,7 @@ final class DriverManager
|
|||||||
|
|
||||||
// check for existing pdo object
|
// check for existing pdo object
|
||||||
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
|
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
|
||||||
throw DoctrineException::invalidPdoInstance();
|
throw DBALException::invalidPdoInstance();
|
||||||
} else if (isset($params['pdo'])) {
|
} else if (isset($params['pdo'])) {
|
||||||
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
} else {
|
} else {
|
||||||
@ -143,14 +140,14 @@ final class DriverManager
|
|||||||
|
|
||||||
// driver
|
// driver
|
||||||
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) {
|
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) {
|
||||||
throw DoctrineException::driverRequired();
|
throw DBALException::driverRequired();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check validity of parameters
|
// check validity of parameters
|
||||||
|
|
||||||
// driver
|
// driver
|
||||||
if ( isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) {
|
if ( isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) {
|
||||||
throw DoctrineException::unknownDriver($params['driver']);
|
throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,15 +7,7 @@ require_once __DIR__ . '/../TestInit.php';
|
|||||||
class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException \Doctrine\Common\DoctrineException
|
* @expectedException \Doctrine\DBAL\DBALException
|
||||||
*/
|
|
||||||
public function testCantInstantiateDriverManager()
|
|
||||||
{
|
|
||||||
$test = new \Doctrine\DBAL\DriverManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Doctrine\Common\DoctrineException
|
|
||||||
*/
|
*/
|
||||||
public function testInvalidPdoInstance()
|
public function testInvalidPdoInstance()
|
||||||
{
|
{
|
||||||
@ -35,7 +27,7 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Doctrine\Common\DoctrineException
|
* @expectedException \Doctrine\DBAL\DBALException
|
||||||
*/
|
*/
|
||||||
public function testCheckParams()
|
public function testCheckParams()
|
||||||
{
|
{
|
||||||
@ -43,7 +35,7 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Doctrine\Common\DoctrineException
|
* @expectedException \Doctrine\DBAL\DBALException
|
||||||
*/
|
*/
|
||||||
public function testInvalidDriver()
|
public function testInvalidDriver()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user