Explorar el Código

Merge remote branch 'kriswallsmith/mongodb/logging-option'

* kriswallsmith/mongodb/logging-option:
  [DoctrineMongoDBBundle] made it possible to disable logging
Fabien Potencier hace 14 años
padre
commit
a604b210c1

+ 13 - 1
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php

@@ -12,10 +12,21 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  */
 class Configuration
 {
+    private $debug;
+
+    /**
+     * Constructor.
+     *
+     * @param Boolean $debug The kernel.debug value
+     */
+    public function __construct($debug)
+    {
+        $this->debug = (Boolean) $debug;
+    }
+
     /**
      * Generates the configuration tree.
      *
-     * @param boolean $kernelDebug The kernel.debug DIC parameter
      * @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface
      */
     public function getConfigTree()
@@ -54,6 +65,7 @@ class Configuration
                     ->builder($this->getMetadataCacheDriverNode())
                     ->scalarNode('connection')->end()
                     ->scalarNode('database')->end()
+                    ->booleanNode('logging')->defaultValue($this->debug)->end()
                     ->fixXmlConfig('mapping')
                     ->builder($this->getMappingsNode())
                 ->end()

+ 6 - 2
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php

@@ -66,7 +66,7 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
         $loader->load('mongodb.xml');
 
         $processor = new Processor();
-        $configuration = new Configuration();
+        $configuration = new Configuration($container->getParameter('kernel.debug'));
         $config = $processor->process($configuration->getConfigTree(), $configs);
 
         // can't currently default this correctly in Configuration
@@ -177,8 +177,12 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
             'setHydratorNamespace' => '%doctrine.odm.mongodb.hydrator_namespace%',
             'setAutoGenerateHydratorClasses' => '%doctrine.odm.mongodb.auto_generate_hydrator_classes%',
             'setDefaultDB' => $defaultDatabase,
-            'setLoggerCallable' => array(new Reference('doctrine.odm.mongodb.logger'), 'logQuery'),
         );
+
+        if ($documentManager['logging']) {
+            $methods['setLoggerCallable'] = array(new Reference('doctrine.odm.mongodb.logger'), 'logQuery');
+        }
+
         foreach ($methods as $method => $arg) {
             if ($odmConfigDef->hasMethodCall($method)) {
                 $odmConfigDef->removeMethodCall($method);