[WebProfilerBundle] inlined a service (closes #4717)

This commit is contained in:
Fabien Potencier 2012-07-03 10:02:51 +02:00
parent 736aa210a2
commit f47b9a6625
2 changed files with 20 additions and 13 deletions

View File

@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
/** /**
* ProfilerController. * ProfilerController.
@ -25,6 +26,8 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
class ProfilerController extends ContainerAware class ProfilerController extends ContainerAware
{ {
protected $templateManager;
/** /**
* Renders a profiler panel for the given token. * Renders a profiler panel for the given token.
* *
@ -49,15 +52,13 @@ class ProfilerController extends ContainerAware
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token)); throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
} }
$templateManager = $this->container->get('web_profiler.template_manager'); return $this->container->get('templating')->renderResponse($this->getTemplateManager()->getName($profile, $panel), array(
return $this->container->get('templating')->renderResponse($templateManager->getName($profile, $panel), array(
'token' => $token, 'token' => $token,
'profile' => $profile, 'profile' => $profile,
'collector' => $profile->getCollector($panel), 'collector' => $profile->getCollector($panel),
'panel' => $panel, 'panel' => $panel,
'page' => $page, 'page' => $page,
'templates' => $templateManager->getTemplates($profile), 'templates' => $this->getTemplateManager()->getTemplates($profile),
'is_ajax' => $request->isXmlHttpRequest(), 'is_ajax' => $request->isXmlHttpRequest(),
)); ));
} }
@ -183,7 +184,7 @@ class ProfilerController extends ContainerAware
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:toolbar.html.twig', array( return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:toolbar.html.twig', array(
'position' => $position, 'position' => $position,
'profile' => $profile, 'profile' => $profile,
'templates' => $this->container->get('web_profiler.template_manager')->getTemplates($profile), 'templates' => $this->getTemplateManager()->getTemplates($profile),
'profiler_url' => $url, 'profiler_url' => $url,
)); ));
} }
@ -309,4 +310,18 @@ class ProfilerController extends ContainerAware
return new Response($phpinfo); return new Response($phpinfo);
} }
protected function getTemplateManager()
{
if (null === $this->templateManager) {
$this->templateManager = new TemplateManager(
$this->container->get('profiler'),
$this->container->get('templating'),
$this->container->get('twig'),
$this->container->getParameter('data_collector.templates')
);
}
return $this->templateManager;
}
} }

View File

@ -6,7 +6,6 @@
<parameters> <parameters>
<parameter key="web_profiler.debug_toolbar.class">Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener</parameter> <parameter key="web_profiler.debug_toolbar.class">Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener</parameter>
<parameter key="web_profiler.template_manager.class">Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager</parameter>
</parameters> </parameters>
<services> <services>
@ -17,12 +16,5 @@
<argument>%web_profiler.debug_toolbar.mode%</argument> <argument>%web_profiler.debug_toolbar.mode%</argument>
<argument>%web_profiler.debug_toolbar.position%</argument> <argument>%web_profiler.debug_toolbar.position%</argument>
</service> </service>
<service id="web_profiler.template_manager" class="%web_profiler.template_manager.class%">
<argument type="service" id="profiler" />
<argument type="service" id="templating.engine.twig" />
<argument type="service" id="twig" />
<argument>%data_collector.templates%</argument>
</service>
</services> </services>
</container> </container>