Skip to content

Commit

Permalink
fixed profiler when using ESI in dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 19, 2011
1 parent 9b60262 commit dff3585
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
Expand Up @@ -9,12 +9,13 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Profiler;
namespace Symfony\Bundle\FrameworkBundle\Profiler;

use Symfony\Component\EventDispatcher\EventInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* ProfilerListener collects data for the current request by listening to the core.response event.
Expand All @@ -26,21 +27,21 @@
*/
class ProfilerListener
{
protected $profiler;
protected $container;
protected $exception;
protected $onlyException;
protected $matcher;

/**
* Constructor.
*
* @param Profiler $profiler A Profiler instance
* @param ContainerInterface $container A ContainerInterface instance
* @param RequestMatcherInterface $matcher A RequestMatcher instance
* @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
*/
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false)
public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false)
{
$this->profiler = $profiler;
$this->container = $container;
$this->matcher = $matcher;
$this->onlyException = $onlyException;
}
Expand Down Expand Up @@ -82,7 +83,7 @@ public function handleResponse(EventInterface $event, Response $response)
return $response;
}

$this->profiler->collect($event->get('request'), $response, $this->exception);
$this->container->get('profiler')->collect($event->get('request'), $response, $this->exception);
$this->exception = null;

return $response;
Expand Down
Expand Up @@ -9,12 +9,12 @@
<parameter key="profiler.storage.class">Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage</parameter>
<parameter key="profiler.storage.file">%kernel.cache_dir%/profiler.db</parameter>
<parameter key="profiler.storage.lifetime">86400</parameter>
<parameter key="profiler_listener.class">Symfony\Component\HttpKernel\Profiler\ProfilerListener</parameter>
<parameter key="profiler_listener.class">Symfony\Bundle\FrameworkBundle\Profiler\ProfilerListener</parameter>
<parameter key="profiler_listener.only_exceptions">false</parameter>
</parameters>

<services>
<service id="profiler" class="%profiler.class%">
<service id="profiler" class="%profiler.class%" scope="request">
<argument type="service" id="profiler.storage" />
<argument type="service" id="logger" on-invalid="null" />
</service>
Expand All @@ -27,7 +27,7 @@
<service id="profiler_listener" class="%profiler_listener.class%">
<tag name="kernel.listener" event="core.response" method="handleResponse" />
<tag name="kernel.listener" event="core.exception" method="handleException" />
<argument type="service" id="profiler" />
<argument type="service" id="service_container" />
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
<argument>%profiler_listener.only_exceptions%</argument>
</service>
Expand Down
Expand Up @@ -130,16 +130,19 @@ public function importAction()
*
* @return Response A Response instance
*/
public function toolbarAction($token = null, $position = null)
public function toolbarAction($token, $position = null)
{
if (null === $token) {
return $this->container->get('response');
}

$profiler = $this->container->get('profiler');
$profiler->disable();

if (null !== $token) {
$profiler = $profiler->loadFromToken($token);
$profiler = $profiler->loadFromToken($token);

if ($profiler->isEmpty()) {
return $this->container->get('response');
}
if ($profiler->isEmpty()) {
return $this->container->get('response');
}

if (null === $position) {
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function testInjectToolbar($content, $expected)

$response = new Response($content);

$m->invoke($listener, $request, $response);
$m->invoke($listener, $response);
$this->assertEquals($expected, $response->getContent());
}

Expand Down
12 changes: 5 additions & 7 deletions src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php
Expand Up @@ -60,19 +60,17 @@ public function handle(EventInterface $event, Response $response)
return $response;
}

$this->injectToolbar($request, $response);
$this->injectToolbar($response);

return $response;
}

/**
* Injects the web debug toolbar into a given HTML string.
* Injects the web debug toolbar into the given Response.
*
* @param string $content The HTML content
*
* @return Response A Response instance
* @param Response $response A Response instance
*/
protected function injectToolbar(Request $request, Response $response)
protected function injectToolbar(Response $response)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
Expand All @@ -82,7 +80,7 @@ protected function injectToolbar(Request $request, Response $response)
$substrFunction = 'substr';
}

$toolbar = "\n".str_replace("\n", '', $this->kernel->render('WebProfilerBundle:Profiler:toolbar'))."\n";
$toolbar = "\n".str_replace("\n", '', $this->kernel->render('WebProfilerBundle:Profiler:toolbar', array('attributes' => array('token' => $response->headers->get('X-Debug-Token')))))."\n";
$content = $response->getContent();

if (false === $pos = $posrFunction($content, '</body>')) {
Expand Down

0 comments on commit dff3585

Please sign in to comment.