From 03bc9350dc1e41d109b38a6bb66a14a0e26a8256 Mon Sep 17 00:00:00 2001 From: beberlei Date: Tue, 8 Dec 2009 19:41:47 +0000 Subject: [PATCH] [2.0] DDC-156 - Allow to pass custom platforms --- lib/Doctrine/DBAL/Connection.php | 11 +++++++++-- lib/Doctrine/DBAL/DBALException.php | 5 +++++ tests/Doctrine/Tests/DBAL/DriverManagerTest.php | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index fb6a31a2e..bef2ae689 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -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(); } diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 94c83bfc4..7d79a87a4 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -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."); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index de7a150df..6e38009c4 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -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()); + } } \ No newline at end of file