Skip to content

Commit f50183b

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Update "Web debug toolbar" profiler docs [DependencyInjection] Allow injecting the current env into php config closures Fix incorrect example for CommandCompletionTester
2 parents fff04ec + 3829c3b commit f50183b

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

console/input.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ to help you unit test the completion logic::
399399
$suggestions = $tester->complete(['']);
400400
$this->assertSame(['Fabien', 'Fabrice', 'Wouter'], $suggestions);
401401

402-
// complete the input with "Fa" as input
402+
// If you filter the values inside your own code (not recommended, unless you
403+
// need to improve performance of e.g. a database query), you can test this
404+
// by passing the user input
403405
$suggestions = $tester->complete(['Fa']);
404406
$this->assertSame(['Fabien', 'Fabrice'], $suggestions);
405407
}

profiler.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,35 @@ production. To do that, create an :doc:`event subscriber </event_dispatcher>`
198198
and listen to the :ref:`kernel.response <component-http-kernel-kernel-response>`
199199
event::
200200

201+
202+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
201203
use Symfony\Component\HttpKernel\Event\ResponseEvent;
204+
use Symfony\Component\HttpKernel\KernelInterface;
202205

203206
// ...
204-
205-
public function onKernelResponse(ResponseEvent $event)
207+
208+
class MySubscriber implements EventSubscriberInterface
206209
{
207-
if (!$event->getKernel()->isDebug()) {
208-
return;
210+
public function __construct(private KernelInterface $kernel)
211+
{
209212
}
213+
214+
// ...
210215

211-
$request = $event->getRequest();
212-
if (!$request->isXmlHttpRequest()) {
213-
return;
214-
}
216+
public function onKernelResponse(ResponseEvent $event)
217+
{
218+
if (!$this->kernel->isDebug()) {
219+
return;
220+
}
215221

216-
$response = $event->getResponse();
217-
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
222+
$request = $event->getRequest();
223+
if (!$request->isXmlHttpRequest()) {
224+
return;
225+
}
226+
227+
$response = $event->getResponse();
228+
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
229+
}
218230
}
219231

220232
.. index::

service_container.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,18 @@ If you want to pass the second, you'll need to :ref:`manually wire the service <
12801280
and the automatically loaded service will be passed - by default - when you type-hint
12811281
``SiteUpdateManager``. That's why creating the alias is a good idea.
12821282

1283+
When using PHP closures to configure your services, it is possible to automatically
1284+
inject the current environment value by adding a string argument named ``$env`` to
1285+
the closure::
1286+
1287+
// config/packages/my_config.php
1288+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1289+
1290+
return function(ContainerConfigurator $configurator, string $env) {
1291+
// `$env` is automatically filled in, so you can configure your
1292+
// services depending on which environment you're on
1293+
};
1294+
12831295
Learn more
12841296
----------
12851297

0 commit comments

Comments
 (0)