Skip to content

Commit ac4eaa4

Browse files
committed
minor #10239 Adding check for environments (aequasi)
This PR was merged into the 4.1 branch. Discussion ---------- Adding check for environments Wasn't sure the best way to change these, but basically, the `@profiler` service (as I understand it) won't exist unless in `dev` or `test` by default. The example should allow for `null` to be passed for the profiler, and do nothing if it is null. Commits ------- 8f91078 Adding check for environments
2 parents bb1b55a + 8f91078 commit ac4eaa4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

profiler/matchers.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ class in your controllers to manage the profiler programmatically::
2121
{
2222
// ...
2323

24-
public function someMethod(Profiler $profiler)
24+
public function someMethod(?Profiler $profiler)
2525
{
26-
// for this particular controller action, the profiler is disabled
27-
$profiler->disable();
26+
// $profiler won't be set if your environment doesn't have the profiler (like prod, by default)
27+
if ($profiler !== null) {
28+
// for this particular controller action, the profiler is disabled
29+
$profiler->disable();
30+
}
2831

2932
// ...
3033
}
@@ -37,13 +40,13 @@ create an alias pointing to the existing ``profiler`` service:
3740

3841
.. code-block:: yaml
3942
40-
# config/services.yaml
43+
# config/dev/services.yaml
4144
services:
4245
Symfony\Component\HttpKernel\Profiler\Profiler: '@profiler'
4346
4447
.. code-block:: xml
4548
46-
<!-- config/services.xml -->
49+
<!-- config/dev/services.xml -->
4750
<?xml version="1.0" encoding="UTF-8" ?>
4851
<container xmlns="http://symfony.com/schema/dic/services"
4952
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -57,7 +60,7 @@ create an alias pointing to the existing ``profiler`` service:
5760
5861
.. code-block:: php
5962
60-
// config/services.php
63+
// config/dev/services.php
6164
use Symfony\Component\HttpKernel\Profiler\Profiler;
6265
6366
$container->setAlias(Profiler::class, 'profiler');

0 commit comments

Comments
 (0)