[WebProfilerBundle] fixed the profiler when the WDT is disabled
This commit is contained in:
parent
600cd415e6
commit
a19c336c18
@ -156,7 +156,7 @@ class ProfilerController extends ContainerAware
|
||||
'profile' => $profile,
|
||||
'templates' => $this->getTemplates($profiler),
|
||||
'profiler_url' => $url,
|
||||
'verbose' => $this->container->get('web_profiler.debug_toolbar')->getVerbose()
|
||||
'verbose' => $this->container->get('web_profiler.debug_toolbar')->isVerbose()
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
|
||||
|
||||
/**
|
||||
* WebProfilerExtension.
|
||||
@ -43,13 +44,19 @@ class WebProfilerExtension extends Extension
|
||||
$configuration = new Configuration();
|
||||
$config = $processor->processConfiguration($configuration, $configs);
|
||||
|
||||
if ($config['toolbar']) {
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('toolbar.xml');
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('toolbar.xml');
|
||||
|
||||
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
|
||||
$container->setParameter('web_profiler.debug_toolbar.verbose', $config['verbose']);
|
||||
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
|
||||
|
||||
if (!$config['toolbar']) {
|
||||
$mode = WebDebugToolbarListener::DISABLED;
|
||||
} elseif ($config['verbose']) {
|
||||
$mode = WebDebugToolbarListener::ENABLED;
|
||||
} else {
|
||||
$mode = WebDebugToolbarListener::ENABLED_MINIMAL;
|
||||
}
|
||||
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
|
||||
|
||||
/**
|
||||
* WebDebugToolbarListener injects the Web Debug Toolbar.
|
||||
@ -29,20 +30,29 @@ use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
*/
|
||||
class WebDebugToolbarListener
|
||||
{
|
||||
const DISABLED = 1;
|
||||
const ENABLED = 2;
|
||||
const ENABLED_MINIMAL = 3;
|
||||
|
||||
protected $templating;
|
||||
protected $interceptRedirects;
|
||||
protected $verbose;
|
||||
protected $mode;
|
||||
|
||||
public function __construct(TwigEngine $templating, $interceptRedirects = false, $verbose = true)
|
||||
public function __construct(TwigEngine $templating, $interceptRedirects = false, $mode = self::ENABLED)
|
||||
{
|
||||
$this->templating = $templating;
|
||||
$this->interceptRedirects = (Boolean) $interceptRedirects;
|
||||
$this->verbose = (Boolean) $verbose;
|
||||
$this->mode = (integer) $mode;
|
||||
}
|
||||
|
||||
public function getVerbose()
|
||||
public function isVerbose()
|
||||
{
|
||||
return $this->verbose;
|
||||
return self::ENABLED === $this->mode;
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return self::DISABLED !== $this->mode;
|
||||
}
|
||||
|
||||
public function onKernelResponse(FilterResponseEvent $event)
|
||||
@ -70,7 +80,8 @@ class WebDebugToolbarListener
|
||||
$response->headers->remove('Location');
|
||||
}
|
||||
|
||||
if (!$response->headers->has('X-Debug-Token')
|
||||
if (self::DISABLED === $this->mode
|
||||
|| !$response->headers->has('X-Debug-Token')
|
||||
|| '3' === substr($response->getStatusCode(), 0, 1)
|
||||
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|
||||
|| 'html' !== $request->getRequestFormat()
|
||||
|
@ -13,7 +13,7 @@
|
||||
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" priority="-128" />
|
||||
<argument type="service" id="templating.engine.twig" />
|
||||
<argument>%web_profiler.debug_toolbar.intercept_redirects%</argument>
|
||||
<argument>%web_profiler.debug_toolbar.verbose%</argument>
|
||||
<argument>%web_profiler.debug_toolbar.mode%</argument>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -91,7 +91,7 @@ class WebProfilerExtensionTest extends TestCase
|
||||
$extension = new WebProfilerExtension();
|
||||
$extension->load(array(array()), $this->container);
|
||||
|
||||
$this->assertFalse($this->container->has('web_profiler.debug_toolbar'));
|
||||
$this->assertFalse($this->container->get('web_profiler.debug_toolbar')->isEnabled());
|
||||
|
||||
$this->assertSaneContainer($this->getDumpedContainer());
|
||||
}
|
||||
@ -99,14 +99,13 @@ class WebProfilerExtensionTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getDebugModes
|
||||
*/
|
||||
public function testToolbarConfig($debug)
|
||||
public function testToolbarConfig($enabled, $verbose)
|
||||
{
|
||||
$this->container->setParameter('kernel.debug', $debug);
|
||||
|
||||
$extension = new WebProfilerExtension();
|
||||
$extension->load(array(array('toolbar' => $debug)), $this->container);
|
||||
$extension->load(array(array('toolbar' => $enabled, 'verbose' => $verbose)), $this->container);
|
||||
|
||||
$this->assertTrue($debug === $this->container->has('web_profiler.debug_toolbar'), '->load() registers web_profiler.debug_toolbar only when toolbar is true');
|
||||
$this->assertSame($enabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
|
||||
$this->assertSame($enabled && $verbose, $this->container->get('web_profiler.debug_toolbar')->isVerbose());
|
||||
|
||||
$this->assertSaneContainer($this->getDumpedContainer());
|
||||
}
|
||||
@ -114,8 +113,10 @@ class WebProfilerExtensionTest extends TestCase
|
||||
public function getDebugModes()
|
||||
{
|
||||
return array(
|
||||
array(true),
|
||||
array(false),
|
||||
array(true, true),
|
||||
array(true, false),
|
||||
array(false, false),
|
||||
array(false, true),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user