Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 src/Symfony/Bundle/DebugBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---

* Wire the `$profilerDumper` argument in `DumpListener`

4.1.0
-----

Expand Down
6 changes: 6 additions & 0 deletions 6 src/Symfony/Bundle/DebugBundle/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@
'priority' => 240,
])

->set('.lazy.data_collector.dump', DumpDataCollector::class)
->factory('current')
->args([[service('data_collector.dump')]])
->lazy()

->set('debug.dump_listener', DumpListener::class)
->args([
service('var_dumper.cloner'),
service('var_dumper.cli_dumper'),
null,
service('.lazy.data_collector.dump'),
])
->tag('kernel.event_subscriber')

Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
* Add `#[IsSignatureValid]` attribute to validate URI signatures
* Make `Profile` final and `Profiler::__sleep()` internal
* Collect the application runner class
* Allow configuring `DumpListener` to use a different dumper when CLI profiling is enabled

7.3
---
Expand Down
16 changes: 14 additions & 2 deletions 16 src/Symfony/Component/HttpKernel/EventListener/DumpListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\EventListener;

use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
Expand All @@ -25,17 +26,28 @@
*/
class DumpListener implements EventSubscriberInterface
{
/**
* @param ?DataDumperInterface $profilerDumper The dumper to use when CLI profiling is enabled.
* If null, the default $dumper will be used instead.
*/
public function __construct(
private ClonerInterface $cloner,
private DataDumperInterface $dumper,
private ?Connection $connection = null,
private ?DataDumperInterface $profilerDumper = null,
) {
}

public function configure(): void
/**
* @param ?ConsoleCommandEvent $event
*/
public function configure(/* ?ConsoleCommandEvent $event = null */): void
{
$event = 1 <= \func_num_args() ? func_get_arg(0) : null;
$input = $event?->getInput();

$cloner = $this->cloner;
$dumper = $this->dumper;
$dumper = !$this->profilerDumper || !$input?->hasOption('profile') || !$input?->getOption('profile') ? $this->dumper : $this->profilerDumper;
$connection = $this->connection;

VarDumper::setHandler(static function ($var, ?string $label = null) use ($cloner, $dumper, $connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

namespace Symfony\Component\HttpKernel\Tests\EventListener;

use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpKernel\EventListener\DumpListener;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
Expand Down Expand Up @@ -62,6 +66,44 @@ public function testConfigure()
throw $exception;
}
}

#[TestWith([false, false, '+foo-+bar-', []])]
#[TestWith([true, false, '+foo-+bar-', []])]
#[TestWith([true, true, '', ['foo-', 'bar-']])]
public function testConfigureWithProfilerDumper(bool $hasOption, bool $option, string $expectedOutput, array $expectedData)
{
$prevDumper = VarDumper::setHandler('var_dump');
VarDumper::setHandler($prevDumper);

$cloner = new MockCloner();
$dumper = new MockDumper();
$profilerDumper = new MockProfilerDumper();

$input = $this->createMock(InputInterface::class);
$input->method('hasOption')->willReturn($hasOption);
$input->method('getOption')->willReturn($option);

ob_start();
$exception = null;
$listener = new DumpListener($cloner, $dumper, null, $profilerDumper);

try {
$listener->configure(new ConsoleCommandEvent(null, $input, new BufferedOutput()));

VarDumper::dump('foo');
VarDumper::dump('bar');

$this->assertSame($expectedOutput, ob_get_clean());
$this->assertSame($expectedData, $profilerDumper->data);
} catch (\Exception $exception) {
}

VarDumper::setHandler($prevDumper);

if (null !== $exception) {
throw $exception;
}
}
}

class MockCloner implements ClonerInterface
Expand All @@ -81,3 +123,15 @@ public function dump(Data $data): ?string
return null;
}
}

class MockProfilerDumper implements DataDumperInterface
{
public array $data = [];

public function dump(Data $data): ?string
{
$this->data[] = $data->getValue();

return null;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.