From 59ae0a6feabea38ebadeca1302d8fb1256ebb873 Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Wed, 8 Jun 2016 21:39:30 +0200 Subject: [PATCH] get the provider work again --- src/Provider/SaxulumWebProfilerProvider.php | 99 +++++++++------------ 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/src/Provider/SaxulumWebProfilerProvider.php b/src/Provider/SaxulumWebProfilerProvider.php index 27c3a6e..25e34e1 100644 --- a/src/Provider/SaxulumWebProfilerProvider.php +++ b/src/Provider/SaxulumWebProfilerProvider.php @@ -25,9 +25,6 @@ public function boot(Application $app) {} */ public function register(Application $app) { - $this->registerDoctrineOrmCollector($app); - $this->registerDoctrineMongoDbOdmCollector($app); - if (isset($app['profiler'])) { $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) { @@ -47,10 +44,46 @@ function (\Twig_Loader_Filesystem $twigLoaderFilesystem) { $app['data_collectors'] = $app->extend('data_collectors', $app->share(function(array $collectors) use ($app) { if(isset($app['doctrine'])) { - $collectors['db'] = function ($app) { $app['saxulum.orm.datacolletor']; }; + $app['saxulum.orm.logger'] = function ($app) { + return new DbalLogger($app['monolog'], $app['stopwatch']); + }; + + $collectors['db'] = $app->share(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'] = $app->share(function ($app) { + $logger = new DoctrineMongoDbLogger($app['monolog']); + $logger->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); + + return $logger; + }); + + $app['saxulum.mongodb.odm.loggers'] = $app->share(function ($app) { + $loggers = array(); + $loggers[] = $app['saxulum.mongodb.odm.logger']; + $loggers[] = $app['saxulum.mongodb.odm.datacolletor']; + + return $loggers; + }); + + $app['saxulum.mongodb.odm.aggregatelogger'] = $app->share(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', $app->share(function(ManagerRegistry $registry) use($aggregatedLogger) { @@ -60,7 +93,12 @@ function (\Twig_Loader_Filesystem $twigLoaderFilesystem) { } )); - $collectors['mongodb'] = function ($app) { return $app['saxulum.mongodb.odm.datacolletor']; }; + $collectors['mongodb'] = $app->share(function ($app) { + $dataCollector = new DoctrineMongoDbDataCollector(); + $dataCollector->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); + + return $dataCollector; + }); } return $collectors; @@ -81,55 +119,4 @@ function (\Twig_Loader_Filesystem $twigLoaderFilesystem) { )); } } - - protected function registerDoctrineOrmCollector(Application $app) - { - $app['saxulum.orm.logger'] = function ($app) { - return new DbalLogger($app['monolog'], $app['stopwatch']); - }; - - $app['saxulum.orm.datacolletor'] = $app->share(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; - }); - } - - protected function registerDoctrineMongoDbOdmCollector(Application $app) - { - $app['saxulum.webprofiler.mongodb.odm.logger.batchthreshold'] = 4; - - $app['saxulum.mongodb.odm.logger'] = $app->share(function ($app) { - $logger = new DoctrineMongoDbLogger($app['monolog']); - $logger->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); - - return $logger; - }); - - $app['saxulum.mongodb.odm.datacolletor'] = $app->share(function ($app) { - $dataCollector = new DoctrineMongoDbDataCollector(); - $dataCollector->setBatchInsertThreshold($app['saxulum.mongodb.odm.logger.batchthreshold']); - - return $dataCollector; - }); - - $app['saxulum.mongodb.odm.loggers'] = $app->share(function ($app) { - $loggers = array(); - $loggers[] = $app['saxulum.mongodb.odm.logger']; - $loggers[] = $app['saxulum.mongodb.odm.datacolletor']; - - return $loggers; - }); - - $app['saxulum.mongodb.odm.aggregatelogger'] = $app->share(function ($app) { - $logger = new DoctrineMongoDbAggregateLogger($app['saxulum.mongodb.odm.loggers']); - - return $logger; - }); - } }