-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Fix dumping by splitting Server/Connection out of Dumper/ServerDumper #27614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,14 @@ | |
<argument type="service" id="debug.file_link_formatter" on-invalid="ignore"></argument> | ||
<argument>%kernel.charset%</argument> | ||
<argument type="service" id="request_stack" /> | ||
<argument>null</argument><!-- var_dumper.cli_dumper or var_dumper.server_dumper when debug.dump_destination is set --> | ||
<argument>null</argument><!-- var_dumper.cli_dumper or var_dumper.server_connection when debug.dump_destination is set --> | ||
</service> | ||
|
||
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener"> | ||
<tag name="kernel.event_subscriber" /> | ||
<argument type="service" id="var_dumper.cloner" /> | ||
<argument type="service" id="var_dumper.cli_dumper" /> | ||
<argument>null</argument> | ||
</service> | ||
|
||
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" public="true" /> | ||
|
@@ -50,9 +51,8 @@ | |
</call> | ||
</service> | ||
|
||
<service id="var_dumper.server_dumper" class="Symfony\Component\VarDumper\Dumper\ServerDumper"> | ||
<argument>null</argument> <!-- server host --> | ||
<argument type="service" id="var_dumper.cli_dumper" /> | ||
<service id="var_dumper.server_connection" class="Symfony\Component\VarDumper\Server\Connection"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be hidden ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, we hide only services with "random" names, not sure this PR should be the one changing this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's true. I'm quite sure I reviewed some PRs hiding some service names. But I'm still fine if the main rule is to hide only "random" names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find any with a quick |
||
<argument /> <!-- server host --> | ||
<argument type="collection"> | ||
<argument type="service" key="source"> | ||
<service class="Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider; | ||
use Symfony\Component\VarDumper\Dumper\HtmlDumper; | ||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface; | ||
use Symfony\Component\VarDumper\Dumper\ServerDumper; | ||
use Symfony\Component\VarDumper\Server\Connection; | ||
|
||
/** | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
|
@@ -38,17 +38,18 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface | |
private $charset; | ||
private $requestStack; | ||
private $dumper; | ||
private $dumperIsInjected; | ||
private $sourceContextProvider; | ||
|
||
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null) | ||
/** | ||
* @param DataDumperInterface|Connection|null $dumper | ||
*/ | ||
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null) | ||
{ | ||
$this->stopwatch = $stopwatch; | ||
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); | ||
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8'; | ||
$this->requestStack = $requestStack; | ||
$this->dumper = $dumper; | ||
$this->dumperIsInjected = null !== $dumper; | ||
|
||
// All clones share these properties by reference: | ||
$this->rootRefs = array( | ||
|
@@ -58,7 +59,7 @@ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, | |
&$this->clonesCount, | ||
); | ||
|
||
$this->sourceContextProvider = $dumper instanceof ServerDumper && isset($dumper->getContextProviders()['source']) ? $dumper->getContextProviders()['source'] : new SourceContextProvider($this->charset); | ||
$this->sourceContextProvider = $dumper instanceof Connection && isset($dumper->getContextProviders()['source']) ? $dumper->getContextProviders()['source'] : new SourceContextProvider($this->charset); | ||
} | ||
|
||
public function __clone() | ||
|
@@ -71,14 +72,17 @@ public function dump(Data $data) | |
if ($this->stopwatch) { | ||
$this->stopwatch->start('dump'); | ||
} | ||
if ($this->isCollected && !$this->dumper) { | ||
$this->isCollected = false; | ||
} | ||
|
||
list('name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt) = $this->sourceContextProvider->getContext(); | ||
|
||
if ($this->dumper) { | ||
if ($this->dumper instanceof Connection) { | ||
if (!$this->dumper->write($data)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the root of the issue: not being able to know if we wrote anything to the server to set |
||
$this->isCollected = false; | ||
} | ||
} elseif ($this->dumper) { | ||
$this->doDump($this->dumper, $data, $name, $file, $line); | ||
} else { | ||
$this->isCollected = false; | ||
} | ||
|
||
$this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt'); | ||
|
@@ -141,9 +145,6 @@ public function serialize() | |
$this->data = array(); | ||
$this->dataCount = 0; | ||
$this->isCollected = true; | ||
if (!$this->dumperIsInjected) { | ||
$this->dumper = null; | ||
} | ||
|
||
return $ser; | ||
} | ||
|
@@ -245,7 +246,7 @@ private function doDump(DataDumperInterface $dumper, $data, $name, $file, $line) | |
}; | ||
$contextDumper = $contextDumper->bindTo($dumper, $dumper); | ||
$contextDumper($name, $file, $line, $this->fileLinkFormat); | ||
} elseif (!$dumper instanceof ServerDumper) { | ||
} else { | ||
$cloner = new VarCloner(); | ||
$dumper->dump($cloner->cloneVar($name.' on line '.$line.':')); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed since VarDumper is a mandatory requirement of DebugBundle