[VarDumper] add support for links in CliDumper
This commit is contained in:
parent
dbf053bc85
commit
e7cd44f5b2
@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* DebugExtension.
|
||||
@ -69,6 +70,14 @@ class DebugExtension extends Extension
|
||||
->setClass(ServerDumpPlaceholderCommand::class)
|
||||
;
|
||||
}
|
||||
|
||||
if (method_exists(CliDumper::class, 'setDisplayOptions')) {
|
||||
$container->getDefinition('var_dumper.cli_dumper')
|
||||
->addMethodCall('setDisplayOptions', array(array(
|
||||
'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
|
||||
)))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,6 +113,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
} else {
|
||||
$dumper = new CliDumper('php://output', $this->charset);
|
||||
if (method_exists($dumper, 'setDisplayOptions')) {
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->data as $dump) {
|
||||
@ -215,6 +218,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
} else {
|
||||
$dumper = new CliDumper('php://output', $this->charset);
|
||||
if (method_exists($dumper, 'setDisplayOptions')) {
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->data as $i => $dump) {
|
||||
|
@ -55,6 +55,10 @@ class CliDumper extends AbstractDumper
|
||||
protected $collapseNextHash = false;
|
||||
protected $expandNextHash = false;
|
||||
|
||||
private $displayOptions = array(
|
||||
'fileLinkFormat' => null,
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -76,6 +80,8 @@ class CliDumper extends AbstractDumper
|
||||
'index' => '34',
|
||||
));
|
||||
}
|
||||
|
||||
$this->displayOptions['fileLinkFormat'] = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,6 +114,16 @@ class CliDumper extends AbstractDumper
|
||||
$this->styles = $styles + $this->styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures display options.
|
||||
*
|
||||
* @param array $displayOptions A map of display options to customize the behavior
|
||||
*/
|
||||
public function setDisplayOptions(array $displayOptions)
|
||||
{
|
||||
$this->displayOptions = $displayOptions + $this->displayOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -427,7 +443,9 @@ class CliDumper extends AbstractDumper
|
||||
$value = substr($value, -$attr['ellipsis']);
|
||||
}
|
||||
|
||||
return $this->style('default', $prefix).$this->style($style, $value);
|
||||
$value = $this->style('default', $prefix).$this->style($style, $value);
|
||||
|
||||
goto href;
|
||||
}
|
||||
|
||||
$style = $this->styles[$style];
|
||||
@ -458,6 +476,16 @@ class CliDumper extends AbstractDumper
|
||||
}
|
||||
}
|
||||
|
||||
href:
|
||||
if ($this->colors) {
|
||||
if (isset($attr['file']) && $href = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) {
|
||||
$attr['href'] = $href;
|
||||
}
|
||||
if (isset($attr['href'])) {
|
||||
$value = "\033]8;;{$attr['href']}\033\\{$value}\033]8;;\033\\";
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -594,4 +622,13 @@ class CliDumper extends AbstractDumper
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getSourceLink($file, $line)
|
||||
{
|
||||
if ($fmt = $this->displayOptions['fileLinkFormat']) {
|
||||
return \is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user