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

Commit 573effd

Browse files
committed
Merge pull request #65 from IceShack/master
Load ContainerBundle only if collect method is called
2 parents b68a3b4 + ad2fdb6 commit 573effd

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

DataCollector/ContainerDataCollector.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
*/
2727
class ContainerDataCollector extends DataCollector
2828
{
29+
/**
30+
* @var Kernel
31+
*/
2932
protected $kernel;
30-
protected $container;
33+
34+
/**
35+
* @var ContainerBuilder
36+
*/
3137
protected $containerBuilder;
3238

3339
/**
@@ -39,8 +45,6 @@ class ContainerDataCollector extends DataCollector
3945
public function __construct(Kernel $kernel, $displayInWdt)
4046
{
4147
$this->kernel = $kernel;
42-
$this->container = $kernel->getContainer();
43-
$this->containerBuilder = $this->getContainerBuilder();
4448
$this->data['display_in_wdt'] = $displayInWdt;
4549
}
4650

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

73+
$this->loadContainerBuilder();
74+
6975
if ($this->containerBuilder !== false) {
7076
foreach ($this->containerBuilder->getParameterBag()->all() as $key => $value) {
7177
$service = substr($key, 0, strpos($key, '.'));
@@ -143,23 +149,27 @@ public function getName()
143149
*
144150
* @author Ryan Weaver <ryan@thatsquality.com>
145151
*
146-
* @return ContainerBuilder
147152
*/
148-
private function getContainerBuilder()
153+
private function loadContainerBuilder()
149154
{
155+
if ($this->containerBuilder !== null) {
156+
return;
157+
}
158+
$container = $this->kernel->getContainer();
150159
if (!$this->getKernel()->isDebug()
151-
|| !$this->container->hasParameter('debug.container.dump')
152-
|| !file_exists($cachedFile = $this->container->getParameter('debug.container.dump'))
160+
|| !$container->hasParameter('debug.container.dump')
161+
|| !file_exists($cachedFile = $container->getParameter('debug.container.dump'))
153162
) {
154-
return false;
163+
$this->containerBuilder = false;
164+
return;
155165
}
156166

157-
$container = new ContainerBuilder();
167+
$containerBuilder = new ContainerBuilder();
158168

159-
$loader = new XmlFileLoader($container, new FileLocator());
169+
$loader = new XmlFileLoader($containerBuilder, new FileLocator());
160170
$loader->load($cachedFile);
161171

162-
return $container;
172+
$this->containerBuilder = $containerBuilder;
163173
}
164174

165175
/**

0 commit comments

Comments
 (0)