| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
namespace SymfonyWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0BundleWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0DoctrineMongoDBBundleWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0DependencyInjection; |
|---|
| 4 |
|
|---|
| 5 |
use SymfonyWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0ComponentWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0ConfigWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0DefinitionWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0BuilderWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0NodeBuilder; |
|---|
| 6 |
use SymfonyWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0ComponentWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0ConfigWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0DefinitionWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0BuilderWarning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0TreeBuilder; |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
class Configuration |
|---|
| 14 |
{ |
|---|
| 15 |
|
|---|
| 16 |
* Generates the configuration tree. |
|---|
| 17 |
* |
|---|
| 18 |
* @param boolean $kernelDebug The kernel.debug DIC parameter |
|---|
| 19 |
* @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface |
|---|
| 20 |
*/ |
|---|
| 21 |
public function getConfigTree() |
|---|
| 22 |
{ |
|---|
| 23 |
$treeBuilder = new TreeBuilder(); |
|---|
| 24 |
$rootNode = $treeBuilder->root('doctrine_mongo_db', 'array'); |
|---|
| 25 |
|
|---|
| 26 |
$this->addDocumentManagersSection($rootNode); |
|---|
| 27 |
$this->addConnectionsSection($rootNode); |
|---|
| 28 |
|
|---|
| 29 |
$rootNode |
|---|
| 30 |
->scalarNode('proxy_namespace')->defaultValue('Proxies')->end() |
|---|
| 31 |
->scalarNode('auto_generate_proxy_classes')->defaultValue(false)->end() |
|---|
| 32 |
->scalarNode('hydrator_namespace')->defaultValue('Hydrators')->end() |
|---|
| 33 |
->scalarNode('auto_generate_hydrator_classes')->defaultValue(false)->end() |
|---|
| 34 |
->scalarNode('default_document_manager')->defaultValue('default')->end() |
|---|
| 35 |
->scalarNode('default_connection')->defaultValue('default')->end() |
|---|
| 36 |
->scalarNode('default_database')->defaultValue('default')->end() |
|---|
| 37 |
; |
|---|
| 38 |
|
|---|
| 39 |
return $treeBuilder->buildTree(); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
* Configures the "document_managers" section |
|---|
| 44 |
*/ |
|---|
| 45 |
private function addDocumentManagersSection(NodeBuilder $rootNode) |
|---|
| 46 |
{ |
|---|
| 47 |
$rootNode |
|---|
| 48 |
->fixXmlConfig('document_manager') |
|---|
| 49 |
->arrayNode('document_managers') |
|---|
| 50 |
->useAttributeAsKey('id') |
|---|
| 51 |
->prototype('array') |
|---|
| 52 |
|
|---|
| 53 |
->treatNullLike(array()) |
|---|
| 54 |
->builder($this->getMetadataCacheDriverNode()) |
|---|
| 55 |
->scalarNode('connection')->end() |
|---|
| 56 |
->scalarNode('database')->end() |
|---|
| 57 |
->fixXmlConfig('mapping') |
|---|
| 58 |
->builder($this->getMappingsNode()) |
|---|
| 59 |
->end() |
|---|
| 60 |
->end() |
|---|
| 61 |
; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
* Adds the configuration for the "connections" key |
|---|
| 66 |
*/ |
|---|
| 67 |
private function addConnectionsSection(NodeBuilder $rootNode) |
|---|
| 68 |
{ |
|---|
| 69 |
$rootNode |
|---|
| 70 |
->fixXmlConfig('connection') |
|---|
| 71 |
->arrayNode('connections') |
|---|
| 72 |
->useAttributeAsKey('id') |
|---|
| 73 |
->prototype('array') |
|---|
| 74 |
->performNoDeepMerging() |
|---|
| 75 |
->scalarNode('server')->defaultNull()->end() |
|---|
| 76 |
->builder($this->addConnectionOptionsNode()) |
|---|
| 77 |
->end() |
|---|
| 78 |
->end() |
|---|
| 79 |
; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
* Returns the array node used for "mappings". |
|---|
| 84 |
* |
|---|
| 85 |
* This is used in two different parts of the tree. |
|---|
| 86 |
* |
|---|
| 87 |
* @param NodeBuilder $rootNode The parent node |
|---|
| 88 |
* @return NodeBuilder |
|---|
| 89 |
*/ |
|---|
| 90 |
protected function getMappingsNode() |
|---|
| 91 |
{ |
|---|
| 92 |
$node = new Nodebuilder('mappings', 'array'); |
|---|
| 93 |
$node |
|---|
| 94 |
->useAttributeAsKey('name') |
|---|
| 95 |
->prototype('array') |
|---|
| 96 |
->beforeNormalization() |
|---|
| 97 |
|
|---|
| 98 |
->ifString() |
|---|
| 99 |
->then(function($v) { return array ('type' => $v); }) |
|---|
| 100 |
->end() |
|---|
| 101 |
|
|---|
| 102 |
// it's guessed in AbstractDoctrineExtension::detectMetadataDriver |
|---|
| 103 |
->treatNullLike(array()) |
|---|
| 104 |
->scalarNode('type')->end() |
|---|
| 105 |
->scalarNode('dir')->end() |
|---|
| 106 |
->scalarNode('prefix')->end() |
|---|
| 107 |
->scalarNode('alias')->end() |
|---|
| 108 |
->booleanNode('is_bundle')->end() |
|---|
| 109 |
->performNoDeepMerging() |
|---|
| 110 |
->end() |
|---|
| 111 |
; |
|---|
| 112 |
|
|---|
| 113 |
return $node; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
* Adds the NodeBuilder for the "options" key of a connection. |
|---|
| 118 |
*/ |
|---|
| 119 |
private function addConnectionOptionsNode() |
|---|
| 120 |
{ |
|---|
| 121 |
$node = new NodeBuilder('options', 'array'); |
|---|
| 122 |
|
|---|
| 123 |
$node |
|---|
| 124 |
->performNoDeepMerging() |
|---|
| 125 |
->addDefaultsIfNotSet() |
|---|
| 126 |
|
|---|
| 127 |
// options go into the Mongo constructor |
|---|
| 128 |
// http://www.php.net/manual/en/mongo.construct.php |
|---|
| 129 |
->booleanNode('connect')->end() |
|---|
| 130 |
->scalarNode('persist')->end() |
|---|
| 131 |
->scalarNode('timeout')->end() |
|---|
| 132 |
->booleanNode('replicaSet')->end() |
|---|
| 133 |
->scalarNode('username')->end() |
|---|
| 134 |
->scalarNode('password')->end() |
|---|
| 135 |
->end(); |
|---|
| 136 |
|
|---|
| 137 |
return $node; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
private function getMetadataCacheDriverNode() |
|---|
| 141 |
{ |
|---|
| 142 |
$node = new NodeBuilder('metadata_cache_driver', 'array'); |
|---|
| 143 |
|
|---|
| 144 |
$node |
|---|
| 145 |
->beforeNormalization() |
|---|
| 146 |
|
|---|
| 147 |
->ifTrue(function($v) { return !is_array($v); }) |
|---|
| 148 |
->then(function($v) { return array('type' => $v); }) |
|---|
| 149 |
->end() |
|---|
| 150 |
->scalarNode('type')->end() |
|---|
| 151 |
->scalarNode('class')->end() |
|---|
| 152 |
->scalarNode('host')->end() |
|---|
| 153 |
->scalarNode('port')->end() |
|---|
| 154 |
->scalarNode('instance_class')->end() |
|---|
| 155 |
->end(); |
|---|
| 156 |
|
|---|
| 157 |
return $node; |
|---|
| 158 |
} |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|