Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit58c7ad4

Browse files
feature#29235 [VarDumper] add support for links in CliDumper (nicolas-grekas)
This PR was merged into the 4.3-dev branch.Discussion----------[VarDumper] add support for links in CliDumper| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Same as#29168 for VarDumper:![capture d ecran de 2018-11-15 20-10-08](https://user-images.githubusercontent.com/243674/48576196-24c04c00-e914-11e8-8a61-c1304c876243.png)Thanks@ostrolucky for this nice discovery!Commits-------e7cd44f [VarDumper] add support for links in CliDumper
2 parentsda4019a +e7cd44f commit58c7ad4

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

‎src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useSymfony\Component\DependencyInjection\Extension\Extension;
1818
useSymfony\Component\DependencyInjection\Loader\XmlFileLoader;
1919
useSymfony\Component\DependencyInjection\Reference;
20+
useSymfony\Component\VarDumper\Dumper\CliDumper;
2021

2122
/**
2223
* DebugExtension.
@@ -69,6 +70,14 @@ public function load(array $configs, ContainerBuilder $container)
6970
->setClass(ServerDumpPlaceholderCommand::class)
7071
;
7172
}
73+
74+
if (method_exists(CliDumper::class,'setDisplayOptions')) {
75+
$container->getDefinition('var_dumper.cli_dumper')
76+
->addMethodCall('setDisplayOptions',array(array(
77+
'fileLinkFormat' =>newReference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
78+
)))
79+
;
80+
}
7281
}
7382

7483
/**

‎src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public function collect(Request $request, Response $response, \Exception $except
113113
$dumper->setDisplayOptions(array('fileLinkFormat' =>$this->fileLinkFormat));
114114
}else {
115115
$dumper =newCliDumper('php://output',$this->charset);
116+
if (method_exists($dumper,'setDisplayOptions')) {
117+
$dumper->setDisplayOptions(array('fileLinkFormat' =>$this->fileLinkFormat));
118+
}
116119
}
117120

118121
foreach ($this->dataas$dump) {
@@ -215,6 +218,9 @@ public function __destruct()
215218
$dumper->setDisplayOptions(array('fileLinkFormat' =>$this->fileLinkFormat));
216219
}else {
217220
$dumper =newCliDumper('php://output',$this->charset);
221+
if (method_exists($dumper,'setDisplayOptions')) {
222+
$dumper->setDisplayOptions(array('fileLinkFormat' =>$this->fileLinkFormat));
223+
}
218224
}
219225

220226
foreach ($this->dataas$i =>$dump) {

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class CliDumper extends AbstractDumper
5555
protected$collapseNextHash =false;
5656
protected$expandNextHash =false;
5757

58+
private$displayOptions =array(
59+
'fileLinkFormat' =>null,
60+
);
61+
5862
/**
5963
* {@inheritdoc}
6064
*/
@@ -76,6 +80,8 @@ public function __construct($output = null, string $charset = null, int $flags =
7680
'index' =>'34',
7781
));
7882
}
83+
84+
$this->displayOptions['fileLinkFormat'] =ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format') ?:'file://%f';
7985
}
8086

8187
/**
@@ -108,6 +114,16 @@ public function setStyles(array $styles)
108114
$this->styles =$styles +$this->styles;
109115
}
110116

117+
/**
118+
* Configures display options.
119+
*
120+
* @param array $displayOptions A map of display options to customize the behavior
121+
*/
122+
publicfunctionsetDisplayOptions(array$displayOptions)
123+
{
124+
$this->displayOptions =$displayOptions +$this->displayOptions;
125+
}
126+
111127
/**
112128
* {@inheritdoc}
113129
*/
@@ -427,7 +443,9 @@ protected function style($style, $value, $attr = array())
427443
$value =substr($value, -$attr['ellipsis']);
428444
}
429445

430-
return$this->style('default',$prefix).$this->style($style,$value);
446+
$value =$this->style('default',$prefix).$this->style($style,$value);
447+
448+
goto href;
431449
}
432450

433451
$style =$this->styles[$style];
@@ -458,6 +476,16 @@ protected function style($style, $value, $attr = array())
458476
}
459477
}
460478

479+
href:
480+
if ($this->colors) {
481+
if (isset($attr['file']) &&$href =$this->getSourceLink($attr['file'],isset($attr['line']) ?$attr['line'] :0)) {
482+
$attr['href'] =$href;
483+
}
484+
if (isset($attr['href'])) {
485+
$value ="\033]8;;{$attr['href']}\033\\{$value}\033]8;;\033\\";
486+
}
487+
}
488+
461489
return$value;
462490
}
463491

@@ -594,4 +622,13 @@ private function isWindowsTrueColor()
594622

595623
return$result;
596624
}
625+
626+
privatefunctiongetSourceLink($file,$line)
627+
{
628+
if ($fmt =$this->displayOptions['fileLinkFormat']) {
629+
return\is_string($fmt) ?strtr($fmt,array('%f' =>$file,'%l' =>$line)) :$fmt->format($file,$line);
630+
}
631+
632+
returnfalse;
633+
}
597634
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp