How to Use Matchers to Enable the Profiler Conditionally
Edit this pageWarning: You are browsing the documentation for Symfony 4.0, which is no longer maintained.
Read the updated version of this page for Symfony 6.1 (the current stable version).
How to Use Matchers to Enable the Profiler Conditionally
Caution
The possibility to use a matcher to enable the profiler conditionally was removed in Symfony 4.0.
Symfony Profiler cannot be enabled/disabled conditionally using matchers, because
that feature was removed in Symfony 4.0. However, you can use the enable()
and disable()
methods of the Profiler
class in your controllers to manage the profiler programmatically:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use Symfony\Component\HttpKernel\Profiler\Profiler;
// ...
class DefaultController
{
// ...
public function someMethod(Profiler $profiler)
{
// for this particular controller action, the profiler is disabled
$profiler->disable();
// ...
}
}
In order for the profiler to be injected into your controller you need to
create an alias pointing to the existing profiler
service:
- YAML
- XML
- PHP
1 2 3
# config/services.yaml
services:
Symfony\Component\HttpKernel\Profiler\Profiler: '@profiler'