From 6be6f40e8400d98e1a1d841f32584d72c0f4dc7c Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 18 Dec 2008 14:21:21 +0000 Subject: [PATCH] Splitting DBAL/ORM configuration. --- .../{Common => DBAL}/Configuration.php | 57 +++---------- lib/Doctrine/DBAL/Connection.php | 7 +- lib/Doctrine/DBAL/DriverManager.php | 4 +- lib/Doctrine/ORM/Configuration.php | 79 +++++++++++++++++++ lib/Doctrine/ORM/EntityManager.php | 6 +- tests/lib/Doctrine_OrmTestCase.php | 2 +- tests/lib/Doctrine_OrmTestSuite.php | 2 +- .../lib/mocks/Doctrine_EntityManagerMock.php | 4 +- 8 files changed, 103 insertions(+), 58 deletions(-) rename lib/Doctrine/{Common => DBAL}/Configuration.php (73%) create mode 100644 lib/Doctrine/ORM/Configuration.php diff --git a/lib/Doctrine/Common/Configuration.php b/lib/Doctrine/DBAL/Configuration.php similarity index 73% rename from lib/Doctrine/Common/Configuration.php rename to lib/Doctrine/DBAL/Configuration.php index 9d211eb7e..acbb45579 100644 --- a/lib/Doctrine/Common/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -19,9 +19,7 @@ * . */ -#namespace Doctrine::Common; - -#use Doctrine::Common::NullObject; +#namespace Doctrine\DBAL; /** * The Configuration is the container for all configuration options of Doctrine. @@ -33,7 +31,7 @@ * @author Roman Borschel * @since 2.0 */ -class Doctrine_Common_Configuration +class Doctrine_DBAL_Configuration { /** * The attributes that are contained in the configuration. @@ -41,21 +39,20 @@ class Doctrine_Common_Configuration * * @var array */ - private $_attributes = array( - 'quoteIdentifiers' => false, - 'indexNameFormat' => '%s_idx', - 'sequenceNameFormat' => '%s_seq', - 'tableNameFormat' => '%s', - 'resultCacheImpl' => null, - 'queryCacheImpl' => null, - 'metadataCacheImpl' => null, - ); + protected $_attributes = array(); /** * Creates a new configuration that can be used for Doctrine. */ public function __construct() - {} + { + $this->_attributes = array( + 'quoteIdentifiers' => false, + 'indexNameFormat' => '%s_idx', + 'sequenceNameFormat' => '%s_seq', + 'tableNameFormat' => '%s' + ); + } public function getQuoteIdentifiers() { @@ -100,40 +97,10 @@ class Doctrine_Common_Configuration $this->_attributes['tableNameFormat'] = $format; } - public function getResultCacheImpl() - { - return $this->_attributes['resultCacheImpl']; - } - - public function setResultCacheImpl(Doctrine_Cache_Interface $cacheImpl) - { - $this->_attributes['resultCacheImpl'] = $cacheImpl; - } - - public function getQueryCacheImpl() - { - return $this->_attributes['queryCacheImpl']; - } - - public function setQueryCacheImpl(Doctrine_Cache_Interface $cacheImpl) - { - $this->_attributes['queryCacheImpl'] = $cacheImpl; - } - - public function getMetadataCacheImpl() - { - return $this->_attributes['metadataCacheImpl']; - } - - public function setMetadataCacheImpl(Doctrine_Cache_Interface $cacheImpl) - { - $this->_attributes['metadataCacheImpl'] = $cacheImpl; - } - public function setCustomTypes(array $types) { foreach ($types as $name => $typeClassName) { - Doctrine_DataType::addCustomType($name, $typeClassName); + Doctrine_DBAL_Types_Type::addCustomType($name, $typeClassName); } } diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index dd32ad3df..2887fa56e 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -21,7 +21,6 @@ #namespace Doctrine\DBAL; -#use Doctrine\Common\Configuration; #use Doctrine\Common\EventManager; #use Doctrine\DBAL\Exceptions\ConnectionException; @@ -83,7 +82,7 @@ class Doctrine_DBAL_Connection /** * The Configuration. * - * @var Doctrine\Common\Configuration + * @var Doctrine\DBAL\Configuration */ protected $_config; @@ -157,7 +156,7 @@ class Doctrine_DBAL_Connection * @param array $params The connection parameters. */ public function __construct(array $params, Doctrine_DBAL_Driver $driver, - Doctrine_Common_Configuration $config = null, + Doctrine_DBAL_Configuration $config = null, Doctrine_Common_EventManager $eventManager = null) { $this->_driver = $driver; @@ -170,7 +169,7 @@ class Doctrine_DBAL_Connection // Create default config and event manager if none given if ( ! $config) { - $this->_config = new Doctrine_Common_Configuration(); + $this->_config = new Doctrine_DBAL_Configuration(); } if ( ! $eventManager) { $this->_eventManager = new Doctrine_Common_EventManager(); diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index af88780b8..e5fb0080f 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -91,12 +91,12 @@ final class Doctrine_DBAL_DriverManager * @return Doctrine::DBAL::Connection */ public static function getConnection(array $params, - Doctrine_Common_Configuration $config = null, + Doctrine_DBAL_Configuration $config = null, Doctrine_Common_EventManager $eventManager = null) { // create default config and event manager, if not set if ( ! $config) { - $config = new Doctrine_Common_Configuration(); + $config = new Doctrine_DBAL_Configuration(); } if ( ! $eventManager) { $eventManager = new Doctrine_Common_EventManager(); diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php new file mode 100644 index 000000000..def2a0efd --- /dev/null +++ b/lib/Doctrine/ORM/Configuration.php @@ -0,0 +1,79 @@ +. + */ + +#namespace Doctrine\ORM; + +#use Doctrine\DBAL\Configuration; + +/** + * The Configuration is the container for all configuration options of Doctrine. + * It combines all configuration options from DBAL & ORM. + * + * INTERNAL: When adding a new configuration option just write a getter/setter + * pair and add the option to the _attributes array with a proper default value. + * + * @author Roman Borschel + * @since 2.0 + */ +class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration +{ + /** + * Creates a new configuration that can be used for Doctrine. + */ + public function __construct() + { + $this->_attributes = array_merge($this->_attributes, array( + 'resultCacheImpl' => null, + 'queryCacheImpl' => null, + 'metadataCacheImpl' => null + )); + } + + public function getResultCacheImpl() + { + return $this->_attributes['resultCacheImpl']; + } + + public function setResultCacheImpl($cacheImpl) + { + $this->_attributes['resultCacheImpl'] = $cacheImpl; + } + + public function getQueryCacheImpl() + { + return $this->_attributes['queryCacheImpl']; + } + + public function setQueryCacheImpl($cacheImpl) + { + $this->_attributes['queryCacheImpl'] = $cacheImpl; + } + + public function getMetadataCacheImpl() + { + return $this->_attributes['metadataCacheImpl']; + } + + public function setMetadataCacheImpl(Doctrine_Cache_Interface $cacheImpl) + { + $this->_attributes['metadataCacheImpl'] = $cacheImpl; + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 2b2e0475f..6a0079bc0 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -151,7 +151,7 @@ class Doctrine_ORM_EntityManager * @param Doctrine_Connection $conn * @param string $name */ - protected function __construct(Doctrine_DBAL_Connection $conn, $name, Doctrine_Common_Configuration $config, + protected function __construct(Doctrine_DBAL_Connection $conn, $name, Doctrine_ORM_Configuration $config, Doctrine_Common_EventManager $eventManager) { $this->_conn = $conn; @@ -722,7 +722,7 @@ class Doctrine_ORM_EntityManager * @param EventManager $eventManager The EventManager instance to use. * @return EntityManager The created EntityManager. */ - public static function create($conn, $name, Doctrine_Common_Configuration $config = null, + public static function create($conn, $name, Doctrine_ORM_Configuration $config = null, Doctrine_Common_EventManager $eventManager = null) { if (is_array($conn)) { @@ -732,7 +732,7 @@ class Doctrine_ORM_EntityManager } if (is_null($config)) { - $config = new Doctrine_Common_Configuration(); + $config = new Doctrine_ORM_Configuration(); } if (is_null($eventManager)) { $eventManager = new Doctrine_Common_EventManager(); diff --git a/tests/lib/Doctrine_OrmTestCase.php b/tests/lib/Doctrine_OrmTestCase.php index bbf74f9fb..7e0d6aced 100644 --- a/tests/lib/Doctrine_OrmTestCase.php +++ b/tests/lib/Doctrine_OrmTestCase.php @@ -15,7 +15,7 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase if (isset($this->sharedFixture['em'])) { $this->_em = $this->sharedFixture['em']; } else { - $config = new Doctrine_Common_Configuration(); + $config = new Doctrine_ORM_Configuration(); $eventManager = new Doctrine_Common_EventManager(); $connectionOptions = array( 'driverClass' => 'Doctrine_DriverMock', diff --git a/tests/lib/Doctrine_OrmTestSuite.php b/tests/lib/Doctrine_OrmTestSuite.php index d04ad07df..cb81e1a8c 100644 --- a/tests/lib/Doctrine_OrmTestSuite.php +++ b/tests/lib/Doctrine_OrmTestSuite.php @@ -10,7 +10,7 @@ class Doctrine_OrmTestSuite extends Doctrine_TestSuite { protected function setUp() { - $config = new Doctrine_Common_Configuration(); + $config = new Doctrine_ORM_Configuration(); $eventManager = new Doctrine_Common_EventManager(); $connectionOptions = array( 'driverClass' => 'Doctrine_DriverMock', diff --git a/tests/lib/mocks/Doctrine_EntityManagerMock.php b/tests/lib/mocks/Doctrine_EntityManagerMock.php index 34be1c3d9..9a6ffd7b2 100644 --- a/tests/lib/mocks/Doctrine_EntityManagerMock.php +++ b/tests/lib/mocks/Doctrine_EntityManagerMock.php @@ -46,11 +46,11 @@ class Doctrine_EntityManagerMock extends Doctrine_ORM_EntityManager * @param Doctrine_EventManager $eventManager * @return unknown */ - public static function create($conn, $name, Doctrine_Common_Configuration $config = null, + public static function create($conn, $name, Doctrine_ORM_Configuration $config = null, Doctrine_Common_EventManager $eventManager = null) { if (is_null($config)) { - $config = new Doctrine_Common_Configuration(); + $config = new Doctrine_ORM_Configuration(); } if (is_null($eventManager)) { $eventManager = new Doctrine_Common_EventManager();