Skip to content
This repository has been archived by the owner on Apr 21, 2018. It is now read-only.

Commit

Permalink
get the provider work again
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Jun 8, 2016
1 parent f5f3fff commit 59ae0a6
Showing 1 changed file with 43 additions and 56 deletions.
99 changes: 43 additions & 56 deletions src/Provider/SaxulumWebProfilerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
});
}
}

0 comments on commit 59ae0a6

Please sign in to comment.