vendor/symfony/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php
changeset 0 7f95f8617b0b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/ConnectionFactory.php	Sat Sep 24 15:40:41 2011 +0200
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\Bundle\DoctrineBundle;
+
+use Doctrine\Common\EventManager;
+use Doctrine\DBAL\Configuration;
+use Doctrine\DBAL\DriverManager;
+use Doctrine\DBAL\Types\Type;
+
+/**
+ * Connection
+ */
+class ConnectionFactory
+{
+    private $typesConfig = array();
+    private $initialized = false;
+
+    /**
+     * Construct.
+     *
+     * @param array $typesConfig
+     */
+    public function __construct(array $typesConfig)
+    {
+        $this->typesConfig = $typesConfig;
+    }
+
+    /**
+     * Create a connection by name.
+     *
+     * @param array         $params
+     * @param Configuration $config
+     * @param EventManager  $eventManager
+     *
+     * @return Doctrine\DBAL\Connection
+     */
+    public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
+    {
+        if (!$this->initialized) {
+            $this->initializeTypes();
+            $this->initialized = true;
+        }
+
+        $connection = DriverManager::getConnection($params, $config, $eventManager);
+
+        if (!empty($mappingTypes)) {
+            $platform = $connection->getDatabasePlatform();
+            foreach ($mappingTypes as $dbType => $doctrineType) {
+                $platform->registerDoctrineTypeMapping($dbType, $doctrineType);
+            }
+        }
+
+        return $connection;
+    }
+
+    private function initializeTypes()
+    {
+        foreach ($this->typesConfig as $type => $className) {
+            if (Type::hasType($type)) {
+                Type::overrideType($type, $className);
+            } else {
+                Type::addType($type, $className);
+            }
+        }
+    }
+}