Skip to content

Commit 59848d6

Browse files
authored
Merge pull request #20 from homersimpsons/feature/multiple-connections
Multiple Connections
2 parents eb760f6 + c762ec7 commit 59848d6

16 files changed

+772
-163
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
/Tests/GeneratedDb*
12
/vendor/
23
/composer.lock
34
/build
4-
/cache
5+
/cache
6+
/.phpunit.result.cache
7+
/var
8+
/tdbm*.lock.yml
9+
/phpunit.xml

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ env:
1111
- COMPOSER_MEMORY_LIMIT=-1
1212
#- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
1313

14+
services:
15+
- mysql
16+
1417
matrix:
1518
fast_finish: true
1619
include:

DependencyInjection/Configuration.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;
55

6+
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
67
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
78
use Symfony\Component\Config\Definition\ConfigurationInterface;
89

@@ -13,11 +14,27 @@ public function getConfigTreeBuilder()
1314
$treeBuilder = new TreeBuilder('tdbm');
1415
$rootNode = $treeBuilder->getRootNode();
1516

16-
$rootNode
17-
->children()
17+
$rootNodeChildren = $rootNode->children();
18+
19+
$this->buildServiceNode($rootNodeChildren);
20+
21+
$rootNodeServices = $rootNodeChildren->arrayNode('databases')->arrayPrototype()->children();
22+
$this->buildServiceNode($rootNodeServices);
23+
$rootNodeServices->end()->end()->end();
24+
25+
$rootNodeChildren->end();
26+
27+
return $treeBuilder;
28+
}
29+
30+
private function buildServiceNode(NodeBuilder $serviceNode): void
31+
{
32+
$serviceNode
1833
->scalarNode('dao_namespace')->defaultValue('App\\Daos')->end()
1934
->scalarNode('bean_namespace')->defaultValue('App\\Beans')->end()
35+
->scalarNode('connection')->defaultValue('doctrine.dbal.default_connection')->end()
2036
->arrayNode('naming')
37+
->addDefaultsIfNotSet()
2138
->children()
2239
->scalarNode('bean_prefix')->defaultValue('')->end()
2340
->scalarNode('bean_suffix')->defaultValue('')->end()
@@ -29,11 +46,8 @@ public function getConfigTreeBuilder()
2946
->scalarNode('base_dao_suffix')->defaultValue('Dao')->end()
3047
->arrayNode('exceptions')
3148
->prototype('scalar')->end()
49+
->end()
3250
->end()
33-
->end()
34-
->end()
35-
;
36-
37-
return $treeBuilder;
51+
->end();
3852
}
3953
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;
6+
7+
8+
class ConnectionConfiguration
9+
{
10+
/** @var string */
11+
private $daoNamespace;
12+
/** @var string */
13+
private $beanNamespace;
14+
/** @var string */
15+
private $connection;
16+
/** @var string */
17+
private $namingBeanPrefix;
18+
/** @var string */
19+
private $namingBeanSuffix;
20+
/** @var string */
21+
private $namingBaseBeanPrefix;
22+
/** @var string */
23+
private $namingBaseBeanSuffix;
24+
/** @var string */
25+
private $namingDaoPrefix;
26+
/** @var string */
27+
private $namingDaoSuffix;
28+
/** @var string */
29+
private $namingBaseDaoPrefix;
30+
/** @var string */
31+
private $namingBaseDaoSuffix;
32+
/** @var array<string, string> */
33+
private $namingExceptions;
34+
35+
/**
36+
* @param array<string, mixed> $connectionParams
37+
*/
38+
public function __construct(array $connectionParams)
39+
{
40+
$this->daoNamespace = $connectionParams['dao_namespace'];
41+
$this->beanNamespace = $connectionParams['bean_namespace'];
42+
$this->connection = $connectionParams['connection'];
43+
$this->namingBeanPrefix = $connectionParams['naming']['bean_prefix'];
44+
$this->namingBeanSuffix = $connectionParams['naming']['bean_suffix'];
45+
$this->namingBaseBeanPrefix = $connectionParams['naming']['base_bean_prefix'];
46+
$this->namingBaseBeanSuffix = $connectionParams['naming']['base_bean_suffix'];
47+
$this->namingDaoPrefix = $connectionParams['naming']['dao_prefix'];
48+
$this->namingDaoSuffix = $connectionParams['naming']['dao_suffix'];
49+
$this->namingBaseDaoPrefix = $connectionParams['naming']['base_dao_prefix'];
50+
$this->namingBaseDaoSuffix = $connectionParams['naming']['base_dao_suffix'];
51+
$this->namingExceptions = $connectionParams['naming']['exceptions'];
52+
}
53+
54+
public function getDaoNamespace(): string
55+
{
56+
return $this->daoNamespace;
57+
}
58+
59+
public function getBeanNamespace(): string
60+
{
61+
return $this->beanNamespace;
62+
}
63+
64+
public function getConnection(): string
65+
{
66+
return $this->connection;
67+
}
68+
69+
public function getNamingBeanPrefix(): string
70+
{
71+
return $this->namingBeanPrefix;
72+
}
73+
74+
public function getNamingBeanSuffix(): string
75+
{
76+
return $this->namingBeanSuffix;
77+
}
78+
79+
public function getNamingBaseBeanPrefix(): string
80+
{
81+
return $this->namingBaseBeanPrefix;
82+
}
83+
84+
public function getNamingBaseBeanSuffix(): string
85+
{
86+
return $this->namingBaseBeanSuffix;
87+
}
88+
89+
public function getNamingDaoPrefix(): string
90+
{
91+
return $this->namingDaoPrefix;
92+
}
93+
94+
public function getNamingDaoSuffix(): string
95+
{
96+
return $this->namingDaoSuffix;
97+
}
98+
99+
public function getNamingBaseDaoPrefix(): string
100+
{
101+
return $this->namingBaseDaoPrefix;
102+
}
103+
104+
public function getNamingBaseDaoSuffix(): string
105+
{
106+
return $this->namingBaseDaoSuffix;
107+
}
108+
109+
/**
110+
* @return array<string, string>
111+
*/
112+
public function getNamingExceptions(): array
113+
{
114+
return $this->namingExceptions;
115+
}
116+
}

0 commit comments

Comments
 (0)