[DoctrineMongoDBBundle] Renaming extension method to overrideParameters(), which is truer to its name.

Also mae this function unset the options after their used. This prevents those values from being available later inside the options array and as parameters.
This commit is contained in:
Ryan Weaver 2011-02-19 11:01:20 -06:00
parent bdd23369e2
commit 9179168e0d

View File

@ -74,22 +74,24 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
$config['metadata_cache_driver'] = array('type' => 'array'); $config['metadata_cache_driver'] = array('type' => 'array');
} }
$this->loadDefaults($config, $container); // set some options as parameters and unset them
$config = $this->overrideParameters($config, $container);
$this->loadConnections($config, $container); $this->loadConnections($config, $container);
$this->loadDocumentManagers($config, $container); $this->loadDocumentManagers($config, $container);
$this->loadConstraints($config, $container); $this->loadConstraints($config, $container);
} }
/** /**
* Loads the default configuration. * Uses some of the extension options to override DI extension parameters.
* *
* @param array $config An array of configuration settings * @param array $options The available configuration options
* @param ContainerBuilder $container A ContainerBuilder instance * @param ContainerBuilder $container A ContainerBuilder instance
*/ */
protected function loadDefaults(array $config, ContainerBuilder $container) protected function overrideParameters($options, ContainerBuilder $container)
{ {
// Allow these application configuration options to override the defaults $overrides = array(
$options = array(
'default_document_manager', 'default_document_manager',
'default_connection', 'default_connection',
'proxy_namespace', 'proxy_namespace',
@ -98,11 +100,17 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
'auto_generate_hydrator_classes', 'auto_generate_hydrator_classes',
'default_database', 'default_database',
); );
foreach ($options as $key) {
if (isset($config[$key])) { foreach ($overrides as $key) {
$container->setParameter('doctrine.odm.mongodb.'.$key, $config[$key]); if (isset($options[$key])) {
$container->setParameter('doctrine.odm.mongodb.'.$key, $options[$key]);
// the option should not be used, the parameter should be referenced
unset($options[$key]);
} }
} }
return $options;
} }
/** /**