renamed template to TemplateManager , moved profiler to the deps of manager

This commit is contained in:
Wodor Wodorski 2012-02-18 11:02:30 +01:00
parent 5fd6ed6cff
commit bc73487382
5 changed files with 14 additions and 22 deletions

View File

@ -52,7 +52,6 @@ class ProfilerController extends ContainerAware
/** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */ /** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */
$templateManager = $this->container->get('web_profiler.profiler_template'); $templateManager = $this->container->get('web_profiler.profiler_template');
$templateManager->setProfiler($profiler);
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,
@ -185,7 +184,6 @@ class ProfilerController extends ContainerAware
/** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */ /** @var $templateManager \Symfony\Bundle\WebProfilerBundle\Profiler\Template */
$templateManager = $this->container->get('web_profiler.profiler_template'); $templateManager = $this->container->get('web_profiler.profiler_template');
$templateManager->setProfiler($profiler);
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,

View File

@ -17,12 +17,12 @@ use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Bundle\TwigBundle\TwigEngine; use Symfony\Bundle\TwigBundle\TwigEngine;
/** /**
* ProfilerController. * Profiler Templates Manager
* *
* @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 Template { class TemplateManager {
/** /**
* @var \Symfony\Bundle\TwigBundle\TwigEngine * @var \Symfony\Bundle\TwigBundle\TwigEngine
@ -49,8 +49,9 @@ class Template {
* @param \Twig_Environment $twig * @param \Twig_Environment $twig
* @param array $templates * @param array $templates
*/ */
public function __construct(TwigEngine $templating, \Twig_Environment $twig, array $templates) public function __construct(Profiler $profiler, TwigEngine $templating, \Twig_Environment $twig, array $templates)
{ {
$this->profiler = $profiler;
$this->templating = $templating; $this->templating = $templating;
$this->twig = $twig; $this->twig = $twig;
$this->templates = $templates; $this->templates = $templates;
@ -87,14 +88,6 @@ class Template {
return $templates; return $templates;
} }
/**
* @param \Symfony\Component\HttpKernel\Profiler\Profiler $profiler
*/
public function setProfiler(Profiler $profiler)
{
$this->profiler = $profiler;
}
/** /**
* Gets template names of templates that are * Gets template names of templates that are
* present in the viewed profile * present in the viewed profile

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\Template</parameter> <parameter key="web_profiler.profiler_template">Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager</parameter>
</parameters> </parameters>
<services> <services>
@ -19,6 +19,7 @@
</service> </service>
<service id="web_profiler.profiler_template" class="%web_profiler.profiler_template%"> <service id="web_profiler.profiler_template" class="%web_profiler.profiler_template%">
<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" />
<argument>%data_collector.templates%</argument> <argument>%data_collector.templates%</argument>

View File

@ -65,6 +65,8 @@ class WebProfilerExtensionTest extends TestCase
$this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'))
->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface')));
$this->container->setParameter('data_collector.templates', array()); $this->container->setParameter('data_collector.templates', array());
$this->container->set('kernel', $this->kernel); $this->container->set('kernel', $this->kernel);
} }

View File

@ -12,14 +12,14 @@
namespace Symfony\Bundle\WebProfilerBundle\Tests\Profiler; namespace Symfony\Bundle\WebProfilerBundle\Tests\Profiler;
use Symfony\Bundle\WebProfilerBundle\Tests\TestCase; use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
use Symfony\Bundle\WebProfilerBundle\Profiler\Template; use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
/** /**
* Test for Template class. * Test for TemplateManager class.
* *
* @author Artur Wielogórski <wodor@wodor.net> * @author Artur Wielogórski <wodor@wodor.net>
*/ */
class TemplateTest extends TestCase class TemplateManagerTest extends TestCase
{ {
/** /**
* @var \Symfony\Bundle\TwigBundle\TwigEngine * @var \Symfony\Bundle\TwigBundle\TwigEngine
@ -42,7 +42,7 @@ class TemplateTest extends TestCase
protected $profile; protected $profile;
/** /**
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\Template * @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
*/ */
protected $templateManager; protected $templateManager;
@ -50,6 +50,7 @@ class TemplateTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$profiler = $this->mockProfiler();
$twigEngine = $this->mockTwigEngine(); $twigEngine = $this->mockTwigEngine();
$twigEnvironment = $this->mockTwigEnvironment(); $twigEnvironment = $this->mockTwigEnvironment();
$templates = array( $templates = array(
@ -58,8 +59,7 @@ class TemplateTest extends TestCase
'data_collector.baz'=>array('baz','FooBundle:Collector:baz') 'data_collector.baz'=>array('baz','FooBundle:Collector:baz')
); );
$this->templateManager = new Template($twigEngine, $twigEnvironment, $templates); $this->templateManager = new TemplateManager($profiler, $twigEngine, $twigEnvironment, $templates);
$this->templateManager->setProfiler($this->mockProfiler());
} }
/** /**
@ -148,7 +148,6 @@ class TemplateTest extends TestCase
->will($this->returnValue('loadedTemplate')); ->will($this->returnValue('loadedTemplate'));
return $this->twigEnvironment; return $this->twigEnvironment;
} }
protected function mockTwigEngine() protected function mockTwigEngine()
@ -162,7 +161,6 @@ class TemplateTest extends TestCase
->will($this->returnValue(true)); ->will($this->returnValue(true));
return $this->twigEngine; return $this->twigEngine;
} }
protected function mockProfiler() { protected function mockProfiler() {