Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DoctrineBundle] Add support to configure DBAL Types through the dbal…
… configuration section.
- Loading branch information
Showing
10 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.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 Symfony\Component\DependencyInjection\ContainerInterface; | ||
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; | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @param array $typesConfig | ||
*/ | ||
public function __construct(array $typesConfig) | ||
{ | ||
$this->typesConfig = $typesConfig; | ||
} | ||
|
||
/** | ||
* Create a connection by name. | ||
* | ||
* @param string $connectionName | ||
* @return Doctrine\DBAL\Connection | ||
*/ | ||
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null) | ||
{ | ||
if (!$this->initialized) { | ||
$this->initializeTypes(); | ||
$this->initialized = true; | ||
} | ||
|
||
return DriverManager::getConnection($params, $config, $eventManager); | ||
} | ||
|
||
private function initializeTypes() | ||
{ | ||
foreach ($this->typesConfig AS $type => $className) { | ||
if (Type::hasType($type)) { | ||
Type::overrideType($type, $className); | ||
} else { | ||
Type::addType($type, $className); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ymfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://www.symfony-project.org/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine" | ||
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd | ||
http://www.symfony-project.org/schema/dic/doctrine http://www.symfony-project.org/schema/dic/doctrine/doctrine-1.0.xsd"> | ||
|
||
<doctrine:dbal> | ||
<doctrine:types> | ||
<doctrine:type name="test" class="Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType" /> | ||
</doctrine:types> | ||
</doctrine:dbal> | ||
</container> |
3 changes: 3 additions & 0 deletions
3
...ymfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/dbal_types.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
doctrine.dbal: | ||
types: | ||
test: Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType |
27 changes: 27 additions & 0 deletions
27
src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
class TestType extends \Doctrine\DBAL\Types\Type | ||
{ | ||
public function getName() | ||
{ | ||
return 'test'; | ||
} | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters