Skip to content
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

Update configuration for 1.4.x driver options #219

Merged
merged 11 commits into from
Feb 4, 2014
98 changes: 62 additions & 36 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Configuration implements ConfigurationInterface
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
Expand All @@ -50,31 +50,14 @@ public function getConfigTreeBuilder()
->scalarNode('default_connection')->end()
->scalarNode('default_database')->defaultValue('default')->end()
->arrayNode('default_commit_options')
->addDefaultsIfNotSet()
->children()
->scalarNode('safe')
->defaultTrue()
->beforeNormalization()
->ifTrue(function($v) { return is_numeric($v); })
->then(function($v) { return (int) $v; })
->end()
->validate()
->ifTrue(function($v) { return is_int($v) && $v < -1; })
->thenInvalid('Integer (-1 or greater) expected for numeric "safe" commit option')
->end()
->end()
->booleanNode('fsync')->defaultFalse()->end()
->scalarNode('timeout')
->defaultValue(\MongoCursor::$timeout)
->beforeNormalization()
->ifTrue(function($v) { return is_numeric($v); })
->then(function($v) { return (int) $v; })
->end()
->validate()
->ifTrue(function($v) { return !is_int($v) || $v < -1; })
->thenInvalid('Integer (-1 or greater) expected for "timeout" commit option')
->end()
->end()
->booleanNode('j')->end()
->scalarNode('timeout')->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be an integer node ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundle still supports Symfony 2.1, so those aren't yet available. Perhaps we can bump it to 2.2 for 3.0. I've created #220 to track the idea.

->scalarNode('w')->end()
->scalarNode('wtimeout')->end()
// Deprecated options
->booleanNode('fsync')->info('Deprecated. Please use the "j" option instead.')->end()
->scalarNode('safe')->info('Deprecated. Please use the "w" option instead.')->end()
->end()
->end()
->end()
Expand All @@ -84,7 +67,9 @@ public function getConfigTreeBuilder()
}

/**
* Configures the "document_managers" section
* Adds the "document_managers" config section.
*
* @param ArrayNodeDefinition $rootNode
*/
private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
{
Expand All @@ -95,6 +80,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
->useAttributeAsKey('id')
->prototype('array')
->treatNullLike(array())
->fixXmlConfig('filter')
->children()
->scalarNode('connection')->end()
->scalarNode('database')->end()
Expand All @@ -108,7 +94,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
->booleanNode('pretty')->defaultValue('%kernel.debug%')->end()
->end()
->end()
->scalarNode('auto_mapping')->defaultFalse()->end()
->booleanNode('auto_mapping')->defaultFalse()->end()
->arrayNode('filters')
->useAttributeAsKey('name')
->prototype('array')
Expand Down Expand Up @@ -137,7 +123,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
->arrayNode('metadata_cache_driver')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function($v) { return !is_array($v); })
->ifString()
->then(function($v) { return array('type' => $v); })
->end()
->children()
Expand All @@ -147,6 +133,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
->scalarNode('port')->end()
->scalarNode('instance_class')->end()
->scalarNode('id')->end()
->scalarNode('namespace')->end()
->end()
->end()
->end()
Expand Down Expand Up @@ -180,7 +167,9 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode)
}

/**
* Adds the configuration for the "connections" key
* Adds the "connections" config section.
*
* @param ArrayNodeDefinition $rootNode
*/
private function addConnectionsSection(ArrayNodeDefinition $rootNode)
{
Expand All @@ -192,19 +181,56 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode)
->prototype('array')
->performNoDeepMerging()
->children()
->scalarNode('server')->defaultNull()->end()
->scalarNode('server')->end()
->arrayNode('options')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->booleanNode('connect')->end()
->scalarNode('persist')->end()
->scalarNode('timeout')->end()
->scalarNode('connectTimeoutMS')->end()
->scalarNode('db')->end()
->booleanNode('journal')->end()
->scalarNode('password')->end()
->enumNode('readPreference')
->values(array('primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'))
->end()
->arrayNode('readPreferenceTags')
->performNoDeepMerging()
->prototype('array')
->beforeNormalization()
// Handle readPreferenceTag XML nodes
->ifTrue(function($v) { return isset($v['readPreferenceTag']); })
->then(function($v) {
// Equivalent of fixXmlConfig() for inner node
if (isset($v['readPreferenceTag']['name'])) {
$v['readPreferenceTag'] = array($v['readPreferenceTag']);
}

return $v['readPreferenceTag'];
})
->end()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->scalarNode('replicaSet')->end()
->booleanNode('slaveOkay')->end()
->scalarNode('socketTimeoutMS')->end()
->booleanNode('ssl')->end()
->scalarNode('username')->end()
->scalarNode('password')->end()
->scalarNode('db')->end()
->scalarNode('w')->end()
->scalarNode('wTimeoutMS')->end()
// Deprecated options
->booleanNode('fsync')->info('Deprecated. Please use the "journal" option instead.')->end()
->booleanNode('slaveOkay')->info('Deprecated. Please use the "readPreference" option instead.')->end()
->scalarNode('timeout')->info('Deprecated. Please use the "connectTimeoutMS" option instead.')->end()
->scalarNode('wTimeout')->info('Deprecated. Please use the "wTimeoutMS" option instead.')->end()
->end()
->validate()
->ifTrue(function($v) { return count($v['readPreferenceTags']) === 0; })
->then(function($v) {
unset($v['readPreferenceTags']);

return $v;
})
->end()
->end()
->end()
Expand Down
138 changes: 120 additions & 18 deletions Resources/config/schema/mongodb-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,131 @@
<xsd:element name="config" type="config" />

<xsd:complexType name="config">
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="port" type="xsd:integer" />
<xsd:attribute name="database" type="xsd:string" />
<xsd:attribute name="proxy-dir" type="xsd:string" />
<xsd:sequence>
<xsd:element name="default-commit-options" type="default-commit-options" minOccurs="0" maxOccurs="1" />
<xsd:element name="connection" type="connection" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="document-manager" type="document-manager" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="auto-generate-hydrator-classes" type="xsd:boolean" />
<xsd:attribute name="auto-generate-proxy-classes" type="xsd:boolean" />
<xsd:attribute name="cache" type="cache" />
<xsd:attribute name="metadata" type="metadata" />
<xsd:attribute name="default-connection" type="xsd:string" />
<xsd:attribute name="default-database" type="xsd:string" />
<xsd:attribute name="default-document-manager" type="xsd:string" />
<xsd:attribute name="hydrator-dir" type="xsd:string" />
<xsd:attribute name="hydrator-namespace" type="xsd:string" />
<xsd:attribute name="proxy-dir" type="xsd:string" />
<xsd:attribute name="proxy-namespace" type="xsd:string" />
</xsd:complexType>

<xsd:simpleType name="cache">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="array" />
<xsd:enumeration value="apc" />
<xsd:enumeration value="memcache" />
<xsd:enumeration value="xcache" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="default-commit-options">
<xsd:attribute name="fsync" type="xsd:boolean" />
<xsd:attribute name="j" type="xsd:boolean" />
<xsd:attribute name="safe" type="xsd:string" />
<xsd:attribute name="timeout" type="xsd:integer" />
<xsd:attribute name="w" type="xsd:string" />
<xsd:attribute name="wtimeout" type="xsd:integer" />
</xsd:complexType>

<xsd:simpleType name="metadata">
<xsd:complexType name="connection">
<xsd:sequence>
<xsd:element name="options" type="connection-options" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="server" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="connection-options">
<xsd:sequence>
<xsd:element name="readPreferenceTags" type="read-preference-tag-set" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="connect" type="xsd:boolean" />
<xsd:attribute name="connectTimeoutMS" type="xsd:integer" />
<xsd:attribute name="db" type="xsd:string" />
<xsd:attribute name="journal" type="xsd:boolean" />
<xsd:attribute name="password" type="xsd:string" />
<xsd:attribute name="readPreference" type="read-preference" />
<xsd:attribute name="replicaSet" type="xsd:string" />
<xsd:attribute name="ssl" type="xsd:boolean" />
<xsd:attribute name="socketTimeoutMS" type="xsd:integer" />
<xsd:attribute name="username" type="xsd:string" />
<xsd:attribute name="w" type="xsd:string" />
<xsd:attribute name="wTimeoutMS" type="xsd:integer" />
<!-- deprecated options -->
<xsd:attribute name="fsync" type="xsd:boolean" />
<xsd:attribute name="slaveOkay" type="xsd:boolean" />
<xsd:attribute name="timeout" type="xsd:integer" />
<xsd:attribute name="wTimeout" type="xsd:integer" />
</xsd:complexType>

<xsd:simpleType name="read-preference">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="annotation" />
<xsd:enumeration value="xml" />
<xsd:enumeration value="yml" />
<xsd:enumeration value="primary" />
<xsd:enumeration value="primaryPreferred" />
<xsd:enumeration value="secondary" />
<xsd:enumeration value="secondaryPreferred" />
<xsd:enumeration value="nearest" />
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="read-preference-tag-set">
<xsd:sequence>
<xsd:element name="readPreferenceTag" type="read-preference-tag" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="read-preference-tag">
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="value" type="xsd:string" use="required" />
</xsd:complexType>

<xsd:complexType name="document-manager">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="filter" type="filter" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="mapping" type="mapping" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="metadata-cache-driver" type="metadata-cache-driver" minOccurs="0" maxOccurs="1" />
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="auto-mapping" type="xsd:boolean" />
<xsd:attribute name="connection" type="xsd:string" />
<xsd:attribute name="database" type="xsd:string" />
<xsd:attribute name="logging" type="xsd:boolean" />
<xsd:attribute name="metadata-cache-driver" type="xsd:string" />
<xsd:attribute name="profiler" type="xsd:boolean" />
<xsd:attribute name="retry-connect" type="xsd:integer" />
<xsd:attribute name="retry-query" type="xsd:integer" />
</xsd:complexType>

<xsd:complexType name="filter">
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="class" type="xsd:string" use="required" />
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="mapping">
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="dir" type="xsd:string" />
<xsd:attribute name="is-bundle" type="xsd:boolean" />
<xsd:attribute name="mapping" type="xsd:boolean" />
<xsd:attribute name="prefix" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="metadata-cache-driver">
<xsd:all>
<xsd:element name="class" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="instance-class" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:integer" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="namespace" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="profiler">
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="pretty" type="xsd:boolean" />
</xsd:complexType>
</xsd:schema>
2 changes: 1 addition & 1 deletion Resources/doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Explicit definition of all the mapped documents is the only necessary
configuration for the ODM and there are several configuration options that you
can control. The following configuration options exist for a mapping:

- ``type`` One of ``annotations``, ``xml``, ``yml``, ``php`` or ``staticphp``.
- ``type`` One of ``annotation``, ``xml``, ``yml``, ``php`` or ``staticphp``.
This specifies which type of metadata type your mapping uses.

- ``dir`` Path to the mapping or entity files (depending on the driver). If
Expand Down
Loading