[WebProfilerBundle] tweaked previous merge

This commit is contained in:
Fabien Potencier 2012-07-02 11:12:51 +02:00
parent 155320ae83
commit 7407773234
3 changed files with 28 additions and 36 deletions

View File

@ -41,7 +41,6 @@ class ProfilerController extends ContainerAware
$panel = $this->container->get('request')->query->get('panel', 'request'); $panel = $this->container->get('request')->query->get('panel', 'request');
$page = $this->container->get('request')->query->get('page', 'home'); $page = $this->container->get('request')->query->get('page', 'home');
if (!$profile = $profiler->loadProfile($token)) { if (!$profile = $profiler->loadProfile($token)) {
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:info.html.twig', array('about' => 'no_token', 'token' => $token)); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:info.html.twig', array('about' => 'no_token', 'token' => $token));
} }
@ -50,8 +49,7 @@ 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));
} }
/** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */ $templateManager = $this->container->get('web_profiler.template_manager');
$templateManager = $this->container->get('web_profiler.profiler_template');
return $this->container->get('templating')->renderResponse($templateManager->getName($profile, $panel), array( return $this->container->get('templating')->renderResponse($templateManager->getName($profile, $panel), array(
'token' => $token, 'token' => $token,
@ -182,13 +180,10 @@ class ProfilerController extends ContainerAware
// the profiler is not enabled // the profiler is not enabled
} }
/** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */
$templateManager = $this->container->get('web_profiler.profiler_template');
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' => $templateManager->getTemplates($profile), 'templates' => $this->container->get('web_profiler.template_manager')->getTemplates($profile),
'profiler_url' => $url, 'profiler_url' => $url,
)); ));
} }

View File

@ -22,32 +22,20 @@ use Symfony\Bundle\TwigBundle\TwigEngine;
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* @author Artur Wielogórski <wodor@wodor.net> * @author Artur Wielogórski <wodor@wodor.net>
*/ */
class TemplateManager { class TemplateManager
{
/**
* @var \Symfony\Bundle\TwigBundle\TwigEngine
*/
protected $templating; protected $templating;
/**
* @var \Twig_Environment
*/
protected $twig; protected $twig;
/**
* @var array
*/
protected $templates; protected $templates;
/**
* @var \Symfony\Component\HttpKernel\Profiler\Profiler
*/
protected $profiler; protected $profiler;
/** /**
* @param \Symfony\Bundle\TwigBundle\TwigEngine $templating * Constructor.
*
* @param Profiler $profiler
* @param TwigEngine $templating
* @param \Twig_Environment $twig * @param \Twig_Environment $twig
* @param array $templates * @param array $templates
*/ */
public function __construct(Profiler $profiler, TwigEngine $templating, \Twig_Environment $twig, array $templates) public function __construct(Profiler $profiler, TwigEngine $templating, \Twig_Environment $twig, array $templates)
{ {
@ -58,10 +46,14 @@ class TemplateManager {
} }
/** /**
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile * Gets the template name for a given panel.
* @param $panel *
* @param Profile $profile
* @param string $panel
*
* @return mixed * @return mixed
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException *
* @throws NotFoundHttpException
*/ */
public function getName(Profile $profile, $panel) public function getName(Profile $profile, $panel)
{ {
@ -75,7 +67,10 @@ class TemplateManager {
} }
/** /**
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile * Gets the templates for a given profile.
*
* @param Profile $profile
*
* @return array * @return array
*/ */
public function getTemplates(Profile $profile) public function getTemplates(Profile $profile)
@ -89,10 +84,12 @@ class TemplateManager {
} }
/** /**
* Gets template names of templates that are * Gets template names of templates that are present in the viewed profile.
* present in the viewed profile *
* @param \Symfony\Component\HttpKernel\Profiler\Profile $profile * @param Profile $profile
*
* @return array * @return array
*
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
protected function getNames(Profile $profile) protected function getNames(Profile $profile)
@ -123,4 +120,4 @@ class TemplateManager {
return $templates; return $templates;
} }
} }

View File

@ -6,7 +6,7 @@
<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.profiler_template">Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager</parameter> <parameter key="web_profiler.template_manager.class">Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager</parameter>
</parameters> </parameters>
<services> <services>
@ -18,7 +18,7 @@
<argument>%web_profiler.debug_toolbar.position%</argument> <argument>%web_profiler.debug_toolbar.position%</argument>
</service> </service>
<service id="web_profiler.profiler_template" class="%web_profiler.profiler_template%"> <service id="web_profiler.template_manager" class="%web_profiler.template_manager.class%">
<argument type="service" id="profiler" /> <argument type="service" id="profiler" />
<argument type="service" id="templating.engine.twig" /> <argument type="service" id="templating.engine.twig" />
<argument type="service" id="twig" /> <argument type="service" id="twig" />