Преглед на файлове

[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.
Ryan Weaver преди 14 години
родител
ревизия
9179168e0d
променени са 1 файла, в които са добавени 17 реда и са изтрити 9 реда
  1. 17 9
      src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php

+ 17 - 9
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php

@@ -74,22 +74,24 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
             $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->loadDocumentManagers($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
      */
-    protected function loadDefaults(array $config, ContainerBuilder $container)
+    protected function overrideParameters($options, ContainerBuilder $container)
     {
-        // Allow these application configuration options to override the defaults
-        $options = array(
+        $overrides = array(
             'default_document_manager',
             'default_connection',
             'proxy_namespace',
@@ -98,11 +100,17 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
             'auto_generate_hydrator_classes',
             'default_database',
         );
-        foreach ($options as $key) {
-            if (isset($config[$key])) {
-                $container->setParameter('doctrine.odm.mongodb.'.$key, $config[$key]);
+
+        foreach ($overrides as $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;
     }
 
     /**