Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add DoctrineMongoDB Configuration #209

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
15 commits merged into from
Mar 9, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
95a2f17
[DoctrineMongoDBBundle] Rewriting several getParameter() calls to use…
weaverryan Feb 18, 2011
ac88b8a
[DoctrineMongoDBBundle] Fixing a test that was passing in the configs…
weaverryan Feb 18, 2011
94da312
[DoctrineMongoDBExtension] Adding a large PHPDoc on the Extension::lo…
weaverryan Feb 18, 2011
a135004
[DoctrineMongoDBBundle] Initial use of the new Configuration class fo…
weaverryan Feb 19, 2011
42a0b22
[DoctrineMongoDBBundle] BC-break: This removes the excess "connection…
weaverryan Feb 19, 2011
95a2a78
[DoctrineMongoDBBundle] Adding a test for the defaults of the Configu…
weaverryan Feb 19, 2011
bdd2336
[DoctrineMongoDBBundle] Removing the "doctrine.odm.mongodb.metadata_c…
weaverryan Feb 19, 2011
9179168
[DoctrineMongoDBBundle] Renaming extension method to overrideParamete…
weaverryan Feb 19, 2011
9ca8f17
[DoctrineMongoDBBundle] Removing the "default_connection" DI paramete…
weaverryan Feb 19, 2011
1e492e2
[DoctrineMongoDBBundle] Refactoring how the document_managers are loa…
weaverryan Feb 19, 2011
7c13e68
[DoctrineMongoDBBundle] Removing unused variable.
weaverryan Feb 19, 2011
68d478f
[DoctrineMongoDBBundle] Changing root node name for consistency.
weaverryan Feb 19, 2011
0fe6f13
[DoctrineMongoDBBundle] Adding a "full" config example in YAML.
weaverryan Feb 19, 2011
62cc352
[DoctrineMongoDBBundle] Removing left-over debug code.
weaverryan Feb 20, 2011
4c947c2
[DoctrineMongoDBBundle] Adding is_bundle node and rearranging a few s…
weaverryan Mar 9, 2011
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* FrameworkExtension configuration structure.
*
* @author Ryan Weaver <[email protected]>
*/
class Configuration
{
/**
* Generates the configuration tree.
*
* @param boolean $kernelDebug The kernel.debug DIC parameter
* @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface
*/
public function getConfigTree()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('doctrine_mongo_db', 'array');

$this->addSingleDocumentManagerSection($rootNode);
$this->addDocumentManagersSection($rootNode);
$this->addSingleConnectionSection($rootNode);
$this->addConnectionsSection($rootNode);

$rootNode
->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
->scalarNode('auto_generate_proxy_classes')->defaultValue(false)->end()
->scalarNode('hydrator_namespace')->defaultValue('Hydrators')->end()
->scalarNode('auto_generate_hydrator_classes')->defaultValue(false)->end()
;

return $treeBuilder->buildTree();
}

/**
* Builds the nodes responsible for the config that supports the single
* document manager.
*/
private function addSingleDocumentManagerSection(NodeBuilder $rootNode)
{
$rootNode
->scalarNode('default_document_manager')->defaultValue('default')->end()
->scalarNode('default_database')->defaultValue('default')->end()
->builder($this->getMetadataCacheDriverNode())
->fixXmlConfig('mapping')
->builder($this->getMappingsNode())
;
}

/**
* Configures the "document_managers" section
*/
private function addDocumentManagersSection(NodeBuilder $rootNode)
{
$rootNode
->fixXmlConfig('document_manager')
->arrayNode('document_managers')
->useAttributeAsKey('id')
->prototype('array')
->performNoDeepMerging()
->treatNullLike(array())
->builder($this->getMetadataCacheDriverNode())
->scalarNode('default_database')->end()
->scalarNode('connection')->end()
->scalarNode('database')->end()
->fixXmlConfig('mapping')
->builder($this->getMappingsNode())
->end()
->end()
;
}

/**
* Configures the single-connection section:
* * default_connection
* * server
* * options
*/
private function addSingleConnectionSection(NodeBuilder $rootNode)
{
$rootNode
->scalarNode('default_connection')->defaultValue('default')->end()
->builder($this->addConnectionServerNode())
->builder($this->addConnectionOptionsNode())
;
}

/**
* Adds the configuration for the "connections" key
*/
private function addConnectionsSection(NodeBuilder $rootNode)
{
$rootNode
->fixXmlConfig('connection')
->arrayNode('connections')
->useAttributeAsKey('id')
->prototype('array')
->performNoDeepMerging()
->builder($this->addConnectionServerNode())
->builder($this->addConnectionOptionsNode())
->end()
->end()
;
}

/**
* Returns the array node used for "mappings".
*
* This is used in two different parts of the tree.
*
* @param NodeBuilder $rootNode The parent node
* @return NodeBuilder
*/
protected function getMappingsNode()
{
$node = new Nodebuilder('mappings', 'array');
$node
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
// if it's not an array, then the scalar is the type key
->ifString()
->then(function($v) { return array ('type' => $v); })
->end()
// I believe that "null" should *not* set the type
// it's guessed in AbstractDoctrineExtension::detectMetadataDriver
->treatNullLike(array())
->scalarNode('type')->end()
->scalarNode('dir')->end()
->scalarNode('prefix')->end()
->scalarNode('alias')->end()
->booleanNode('is_bundle')->end()
->performNoDeepMerging()
->end()
;

return $node;
}

/**
* Adds the NodeBuilder for the "server" key of a connection.
*/
private function addConnectionServerNode()
{
$node = new NodeBuilder('server', 'scalar');

$node
->defaultValue(null)
->end();

return $node;
}

/**
* Adds the NodeBuilder for the "options" key of a connection.
*/
private function addConnectionOptionsNode()
{
$node = new NodeBuilder('options', 'array');

$node
->performNoDeepMerging()
->addDefaultsIfNotSet() // adds an empty array of omitted

// options go into the Mongo constructor
// http://www.php.net/manual/en/mongo.construct.php
->booleanNode('connect')->end()
->scalarNode('persist')->end()
->scalarNode('timeout')->end()
->booleanNode('replicaSet')->end()
->scalarNode('username')->end()
->scalarNode('password')->end()
->end();

return $node;
}

private function getMetadataCacheDriverNode()
{
$node = new NodeBuilder('metadata_cache_driver', 'array');

$node
->beforeNormalization()
// if scalar
->ifTrue(function($v) { return !is_array($v); })
->then(function($v) { return array('type' => $v); })
->end()
->scalarNode('type')->end()
->scalarNode('class')->end()
->scalarNode('host')->end()
->scalarNode('port')->end()
->scalarNode('instance_class')->end()
->end();

return $node;
}
}
Loading