8000 Doctrine config by stof · Pull Request #99 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Doctrine config #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
7 commits merged into from
Mar 9, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made mandatory to have at least one entity manager when using the ORM…
… and one connection when using DBAL
  • Loading branch information
stof committed Mar 9, 2011
commit 527749ca3fd3f2c8ff42ec69b7bea61b66adcb5e
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ private function addDbalSection(NodeBuilder $node)
{
$node
->arrayNode('dbal')
->beforeNormalization()
->ifNull()
->then(function($v) { return array (); }) // Let use the default values with the subsequent closure.
->end()
->beforeNormalization()
->ifTrue(function($v){ return is_array($v) && !array_key_exists('connections', $v) && !array_key_exists('connection', $v); })
->then(function($v) {
Expand All @@ -61,7 +65,7 @@ private function addDbalSection(NodeBuilder $node)
return $v;
})
->end()
->scalarNode('default_connection')->cannotBeEmpty()->defaultValue('default')->end()
->scalarNode('default_connection')->isRequired()->cannotBeEmpty()->end()
->fixXmlConfig('type')
->arrayNode('types')
->useAttributeAsKey('name')
Expand All @@ -82,6 +86,7 @@ private function getDbalConnectionsNode()
{
$node = new NodeBuilder('connections', 'array');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->scalarNode('dbname')->end()
Expand Down Expand Up @@ -132,8 +137,7 @@ private function addOrmSection(NodeBuilder $node)
return $v;
})
->end()
->scalarNode('default_entity_manager')->cannotBeEmpty()->defaultValue('default')->end()
->scalarNode('default_connection')->cannotBeEmpty()->defaultValue('default')->end()
->scalarNode('default_entity_manager')->isRequired()->cannotBeEmpty()->end()
->booleanNode('auto_generate_proxy_classes')->defaultFalse()->end()
->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end()
->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
Expand All @@ -147,6 +151,7 @@ private function getOrmEntityManagersNode()
{
$node = new NodeBuilder('entity_managers', 'array');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->addDefaultsIfNotSet()
Expand All @@ -157,6 +162,8 @@ private function getOrmEntityManagersNode()
->scalarNode('class_metadata_factory_name')->defaultValue('%doctrine.orm.class_metadata_factory_name%')->end()
->fixXmlConfig('mapping')
->arrayNode('mappings')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('orm.xml');

$options = array('default_entity_manager', 'default_connection', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace');
$options = array('default_entity_manager', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace');
foreach ($options as $key) {
$container->setParameter('doctrine.orm.'.$key, $config[$key]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function testSingleEntityManagerConfiguration()
$container = $this->getContainer();
$loader = new DoctrineExtension();

$loader->load(array(array('dbal' => array(), 'orm' => array())), $container);
$loader->load(array(array('dbal' => array(), 'orm' => array('mappings' => array('YamlBundle' => array())))), $container);

$definition = $container->getDefinition('doctrine.dbal.default_connection');
$this->assertEquals('Doctrine\DBAL\Connection', $definition->getClass());
Expand All @@ -208,8 +208,6 @@ public function testLoadSimpleSingleConnection()
$loader = new DoctrineExtension();
$container->registerExtension($loader);

$loader->load(array(array('dbal' => array(), 'orm' => array())), $container);

$this->loadFromFile($container, 'orm_service_simple_single_entity_manager');

$container->getCompilerPassConfig()->setOptimizationPasses(array());
Expand Down Expand Up @@ -269,6 +267,8 @@ public function testLoadSingleConnection()
'password' => 'sqlite_s3cr3t',
'dbname' => 'sqlite_db',
'memory' => true,
'logging' => false,
'charset' => 'UTF-8'
),
new Reference('doctrine.dbal.default_connection.configuration'),
new Reference('doctrine.dbal.default_connection.event_manager')
Expand Down Expand Up @@ -307,9 +307,9 @@ public function testLoadMultipleConnections()
$this->assertEquals('doctrine.dbal.conn1_connection.configuration', (string) $args[1]);
$this->assertEquals('doctrine.dbal.conn1_connection.event_manager', (string) $args[2]);

$this->assertEquals('doctrine.orm.dm2_entity_manager', (string) $container->getAlias('doctrine.orm.entity_manager'));
$this->assertEquals('doctrine.orm.em2_entity_manager', (string) $container->getAlias('doctrine.orm.entity_manager'));

$definition = $container->getDefinition('doctrine.orm.dm1_entity_manager');
$definition = $container->getDefinition('doctrine.orm.em1_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
Expand All @@ -319,7 +319,7 @@ public function testLoadMultipleConnections()
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
$this->assertEquals('doctrine.dbal.conn1_connection', (string) $arguments[0]);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
$this->assertEquals('doctrine.orm.dm1_configuration', (string) $arguments[1]);
$this->assertEquals('doctrine.orm.em1_configuration', (string) $arguments[1]);

$definition = $container->getDefinition('doctrine.dbal.conn2_connection');
$this->assertEquals('Doctrine\DBAL\Connection', $definition->getClass());
Expand All @@ -331,7 +331,7 @@ public function testLoadMultipleConnections()
$this->assertEquals('doctrine.dbal.conn2_connection.configuration', (string) $args[1]);
$this->assertEquals('doctrine.dbal.conn2_connection.event_manager', (string) $args[2]);

$definition = $container->getDefinition('doctrine.orm.dm2_entity_manager');
$definition = $container->getDefinition('doctrine.orm.em2_entity_manager');
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getClass());
$this->assertEquals('%doctrine.orm.entity_manager_class%', $definition->getFactoryClass());
$this->assertEquals('create', $definition->getFactoryMethod());
Expand All @@ -341,15 +341,15 @@ public function testLoadMultipleConnections()
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
$this->assertEquals('doctrine.dbal.conn2_connection', (string) $arguments[0]);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
$this->assertEquals('doctrine.orm.dm2_configuration', (string) $arguments[1]);
$this->assertEquals('doctrine.orm.em2_configuration', (string) $arguments[1]);

$definition = $container->getDefinition('doctrine.orm.dm1_metadata_cache');
$definition = $container->getDefinition('doctrine.orm.em1_metadata_cache');
$this->assertEquals('%doctrine.orm.cache.xcache_class%', $definition->getClass());

$definition = $container->getDefinition('doctrine.orm.dm1_query_cache');
$definition = $container->getDefinition('doctrine.orm.em1_query_cache');
$this->assertEquals('%doctrine.orm.cache.array_class%', $definition->getClass());

$definition = $container->getDefinition('doctrine.orm.dm1_result_cache');
$definition = $container->getDefinition('doctrine.orm.em1_result_cache');
$this->assertEquals('%doctrine.orm.cache.array_class%', $definition->getClass());
}

Expand Down Expand Up @@ -469,10 +469,10 @@ public function testEntityManagerMetadataCacheDriverConfiguration()
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();

$definition = $container->getDefinition('doctrine.orm.dm1_metadata_cache');
$definition = $container->getDefinition('doctrine.orm.em1_metadata_cache');
$this->assertDICDefinitionClass($definition, '%doctrine.orm.cache.xcache_class%');

$definition = $container->getDefinition('doctrine.orm.dm2_metadata_cache');
$definition = $container->getDefinition('doctrine.orm.em2_metadata_cache');
$this->assertDICDefinitionClass($definition, '%doctrine.orm.cache.apc_class%');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal>
<dbal default-connection="mysql">
<connection
name="mysql"
dbname="mysql_db"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal>
<dbal default-connection="mysql">
<connection
name="mysql"
dbname="mysql_db"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal>
<dbal default-connection="default">
<type name="test" class="Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType" />
<connection name="default" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<orm
auto-generate-proxy-classes="false"
metadata-cache-driver="apc"
/>
>
<mapping name="YamlBundle" />
</orm>
</config>
</srv:container>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<orm default-entity-manager="dm2" default-connection="conn1">
<orm default-entity-manager="em2">
<entity-manager name="em1">
<mapping name="AnnotationsBundle" />
</entity-manager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
memory="true" />
</dbal>

<orm default-entity-manager="dm2" default-connection="conn1" auto-generate-proxy-classes="true">
<entity-manager name="dm1" metadata-cache-driver="xcache" connection="conn1" />
<entity-manager name="dm2" connection="conn2" metadata-cache-driver="apc" />
<orm default-entity-manager="em2" auto-generate-proxy-classes="true">
<entity-manager name="em1" metadata-cache-driver="xcache" connection="conn1">
<mapping name="YamlBundle" />
</entity-manager>
<entity-manager name="em2" connection="conn2" metadata-cache-driver="apc">
<mapping name="YamlBundle" />
</entity-manager>
</orm>
</config>
</srv:container>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<port>11211</port>
<instance-class>Memcache</instance-class>
</metadata-cache-driver>
<mapping name="YamlBundle" />
</orm>
</config>
</srv:container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</srv:parameters>

<config>
<dbal>
<dbal default-connection="default">
<connection
name="default"
driver="pdo_sqlite"
Expand All @@ -22,9 +22,7 @@
</dbal>

<orm
metadata-cache-driver="apc"
default-entity-manager="dm2"
default-connection="conn1"
default-entity-manager="default"
auto-generate-proxy-classes="true"
>
<entity-manager name="default" connection="default">
Expand All @@ -34,6 +32,7 @@
<port>11211</port>
<instance-class>Memcache</instance-class>
</metadata-cache-driver>
<mapping name="YamlBundle" />
</entity-manager>
</orm>
</config>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
doctrine:
dbal:
default_connection: mysql
connections:
mysql:
dbname: mysql_db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
doctrine:
dbal:
default_connection: mysql
connections:
mysql:
dbname: mysql_db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
doctrine:
dbal:
default_connection: default
types:
test: Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType
test: Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType
connections:
default: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver: apc
mappings:
YamlBundle: ~
doctrine:
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
orm:
default_entity_manager: em2
entity_managers:
default_entity_manager: dm2
default_connection: conn1
em1:
mappings:
AnnotationsBundle: ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:

doctrine:
dbal:
default_connection: conn1
connections:
conn1:
driver: pdo_sqlite
Expand All @@ -18,13 +19,16 @@ doctrine:
memory: true

orm:
default_entity_manager: dm2
default_connection: conn1
default_entity_manager: em2
auto_generate_proxy_classes: true
entity_managers:
dm1:
em1:
metadata_cache_driver: xcache
connection: conn1
dm2:
mappings:
YamlBundle: ~
em2:
metadata_cache_driver: apc
connection: conn2
mappings:
YamlBundle: ~
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
doctrine:
dbal: ~

orm:
mappings:
YamlBundle: ~
metadata_cache_driver:
type: memcache
class: Doctrine\Common\Cache\MemcacheCache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
Expand All @@ -9,14 +10,14 @@ doctrine:
memory: true

orm:
metadata_cache_driver: apc
default_entity_manager: dm2
default_connection: conn1
proxy_namespace: Proxies
auto_generate_proxy_classes: true
entity_managers:
default:
connection: default
mappings:
YamlBundle: ~
metadata_cache_driver:
type: memcache
class: Doctrine\Common\Cache\MemcacheCache
Expand Down
0