Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Load ContainerBundle only if collect method is called
Browse files Browse the repository at this point in the history
The profiler could get deactivated during a request, so we wouldn't need the overhead of loading the container bundle
  • Loading branch information
Moritz Schröder committed Jun 17, 2015
1 parent b68a3b4 commit 7b79b96
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions DataCollector/ContainerDataCollector.php
Expand Up @@ -26,10 +26,16 @@
*/
class ContainerDataCollector extends DataCollector
{
/**
* @var Kernel
*/
protected $kernel;
protected $container;
protected $containerBuilder;

/**
* @var ContainerBuilder
*/
protected $containerBuilder;

/**
* Constructor for the Container Datacollector
*
Expand All @@ -39,8 +45,6 @@ class ContainerDataCollector extends DataCollector
public function __construct(Kernel $kernel, $displayInWdt)
{
$this->kernel = $kernel;
$this->container = $kernel->getContainer();
$this->containerBuilder = $this->getContainerBuilder();
$this->data['display_in_wdt'] = $displayInWdt;
}

Expand All @@ -66,6 +70,8 @@ public function collect(Request $request, Response $response, \Exception $except
$parameters = array();
$services = array();

$this->loadContainerBuilder();

if ($this->containerBuilder !== false) {
foreach ($this->containerBuilder->getParameterBag()->all() as $key => $value) {
$service = substr($key, 0, strpos($key, '.'));
Expand Down Expand Up @@ -143,23 +149,27 @@ public function getName()
*
* @author Ryan Weaver <ryan@thatsquality.com>
*
* @return ContainerBuilder
*/
private function getContainerBuilder()
private function loadContainerBuilder()
{
if ($this->containerBuilder !== null) {
return;
}
$container = $this->kernel->getContainer();
if (!$this->getKernel()->isDebug()
|| !$this->container->hasParameter('debug.container.dump')
|| !file_exists($cachedFile = $this->container->getParameter('debug.container.dump'))
|| !$container->hasParameter('debug.container.dump')
|| !file_exists($cachedFile = $container->getParameter('debug.container.dump'))
) {
return false;
$this->containerBuilder = false;
return;
}

$container = new ContainerBuilder();
$containerBuilder = new ContainerBuilder();

$loader = new XmlFileLoader($container, new FileLocator());
$loader = new XmlFileLoader($containerBuilder, new FileLocator());
$loader->load($cachedFile);

return $container;
$this->containerBuilder = $containerBuilder;
}

/**
Expand Down

0 comments on commit 7b79b96

Please sign in to comment.