/**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     if (isset($app['profiler'])) {
         $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) {
             $twig->addExtension(new DoctrineExtension());
             return $twig;
         }));
         $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) {
             $twigLoaderFilesystem->addPath(dirname(__DIR__) . '/Resources/views', 'SaxulumWebProfilerProvider');
             return $twigLoaderFilesystem;
         }));
         $dataCollectors = $app['data_collectors'];
         $dataCollectors['db'] = $app->share(function ($app) {
             $dataCollector = new DoctrineDataCollector($app['doctrine']);
             foreach ($app['doctrine']->getConnectionNames() as $name) {
                 $logger = new DbalLogger($app['monolog'], $app['stopwatch']);
                 $app['doctrine']->getConnection($name)->getConfiguration()->setSQLLogger($logger);
                 $dataCollector->addLogger($name, $logger);
             }
             return $dataCollector;
         });
         $app['data_collectors'] = $dataCollectors;
         $dataCollectorTemplates = $app['data_collector.templates'];
         $dataCollectorTemplates[] = array('db', '@SaxulumWebProfilerProvider/Collector/db.html.twig');
         $app['data_collector.templates'] = $dataCollectorTemplates;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     if (isset($app['profiler'])) {
         $app['twig'] = $app->extend('twig', function (\Twig_Environment $twig) {
             $twig->addExtension(new DoctrineExtension());
             return $twig;
         });
         $app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) {
             $twigLoaderFilesystem->addPath(dirname(__DIR__) . '/Resources/views', 'SaxulumWebProfilerProvider');
             return $twigLoaderFilesystem;
         });
         $app['data_collectors'] = $app->extend('data_collectors', function (array $collectors) use($app) {
             if (isset($app['doctrine'])) {
                 $app['saxulum.orm.logger'] = $app->factory(function ($app) {
                     return new DbalLogger($app['monolog'], $app['stopwatch']);
                 });
                 $collectors['db'] = function ($app) {
                     $dataCollector = new DoctrineDataCollector($app['doctrine']);
                     foreach ($app['doctrine']->getConnectionNames() as $name) {
                         $logger = $app['saxulum.orm.logger'];
                         $app['doctrine']->getConnection($name)->getConfiguration()->setSQLLogger($logger);
                         $dataCollector->addLogger($name, $logger);
                     }
                     return $dataCollector;
                 };
             }
             if (isset($app['doctrine_mongodb'])) {
                 $app['saxulum.webprofiler.mongodb.odm.logger.batchthreshold'] = 4;
                 $app['saxulum.mongodb.odm.logger'] = function ($app) {
                     $logger = new DoctrineMongoDbLogger($app['monolog']);
                     $logger->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']);
                     return $logger;
                 };
                 $app['saxulum.mongodb.odm.loggers'] = function ($app) {
                     $loggers = array();
                     $loggers[] = $app['saxulum.mongodb.odm.logger'];
                     $loggers[] = $app['saxulum.mongodb.odm.datacolletor'];
                     return $loggers;
                 };
                 $app['saxulum.mongodb.odm.aggregatelogger'] = function ($app) {
                     $logger = new DoctrineMongoDbAggregateLogger($app['saxulum.mongodb.odm.loggers']);
                     return $logger;
                 };
                 $aggregatedLogger = $app['saxulum.mongodb.odm.aggregatelogger'];
                 $app['doctrine_mongodb'] = $app->extend('doctrine_mongodb', function (ManagerRegistry $registry) use($aggregatedLogger) {
                     foreach ($registry->getConnectionNames() as $name) {
                         $registry->getConnection($name)->getConfiguration()->setLoggerCallable(array($aggregatedLogger, 'logQuery'));
                     }
                 });
                 $collectors['mongodb'] = function ($app) {
                     $dataCollector = new DoctrineMongoDbDataCollector();
                     $dataCollector->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']);
                     return $dataCollector;
                 };
             }
             return $collectors;
         });
         $app['data_collector.templates'] = $app->extend('data_collector.templates', function (array $dataCollectorTemplates) use($app) {
             if (isset($app['doctrine'])) {
                 $dataCollectorTemplates[] = array('db', '@SaxulumWebProfilerProvider/Collector/db.html.twig');
             }
             if (isset($app['doctrine_mongodb'])) {
                 $dataCollectorTemplates[] = array('mongodb', '@SaxulumWebProfilerProvider/Collector/mongodb.html.twig');
             }
             return $dataCollectorTemplates;
         });
     }
 }