Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[VarDumper] add support for links in CliDumper #29235

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

Merged
merged 1 commit into from
Dec 13, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\VarDumper\Dumper\CliDumper;

/**
* DebugExtension.
Expand Down Expand Up @@ -69,6 +70,14 @@ public function load(array $configs, ContainerBuilder $container)
->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),
)))
;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public function collect(Request $request, Response $response, \Exception $except
$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) {
Expand Down Expand Up @@ -215,6 +218,9 @@ public function __destruct()
$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) {
Expand Down
39 changes: 38 additions & 1 deletion src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class CliDumper extends AbstractDumper
protected $collapseNextHash = false;
protected $expandNextHash = false;

private $displayOptions = array(
'fileLinkFormat' => null,
);

/**
* {@inheritdoc}
*/
Expand All @@ -76,6 +80,8 @@ public function __construct($output = null, string $charset = null, int $flags =
'index' => '34',
));
}

$this->displayOptions['fileLinkFormat'] = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f';
}

/**
Expand Down Expand Up @@ -108,6 +114,16 @@ public function setStyles(array $styles)
$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}
*/
Expand Down Expand Up @@ -427,7 +443,9 @@ protected function style($style, $value, $attr = array())
$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];
Expand Down Expand Up @@ -458,6 +476,16 @@ protected function style($style, $value, $attr = array())
}
}

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;
}

Expand Down Expand Up @@ -594,4 +622,13 @@ private function isWindowsTrueColor()

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;
}
}