1
0
mirror of synced 2025-01-31 04:21:44 +03:00

[2.0] DDC-156 - Allow to pass custom platforms

This commit is contained in:
beberlei 2009-12-08 19:41:47 +00:00
parent 845c85552e
commit 03bc9350dc
3 changed files with 26 additions and 2 deletions

View File

@ -22,7 +22,8 @@
namespace Doctrine\DBAL;
use Doctrine\Common\EventManager,
Doctrine\Common\DoctrineException;
Doctrine\Common\DoctrineException,
Doctrine\DBAL\DBALException;
/**
* A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like
@ -178,7 +179,13 @@ class Connection
$this->_config = $config;
$this->_eventManager = $eventManager;
$this->_platform = $driver->getDatabasePlatform();
if (!isset($params['platform'])) {
$this->_platform = $driver->getDatabasePlatform();
} else if($params['platform'] instanceof \Doctrine\DBAL\Platforms\AbstractPlatform) {
$this->_platform = $params['platform'];
} else {
throw DBALException::invalidPlatformSpecified();
}
$this->_transactionIsolationLevel = $this->_platform->getDefaultTransactionIsolationLevel();
}

View File

@ -8,4 +8,9 @@ class DBALException extends \Exception
{
return new self("Operation '$method' is not supported.");
}
public static function invalidPlatformSpecified()
{
return new self("Invalid 'platform' option specified, need to give an instance of \Doctrine\DBAL\Platforms\AbstractPlatform.");
}
}

View File

@ -49,4 +49,16 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
{
$conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
}
public function testCustomPlatform()
{
$mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
$options = array(
'pdo' => new \PDO('sqlite::memory:'),
'platform' => $mockPlatform
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$this->assertSame($mockPlatform, $conn->getDatabasePlatform());
}
}