Skip to content

Commit 18cfbab

Browse files
[FrameworkBundle] Add %debug.file_link_format% with remapping for IDE links
1 parent e5f5340 commit 18cfbab

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

DataCollector/DumpDataCollector.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
4040

4141
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null)
4242
{
43+
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
44+
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
45+
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
46+
$i = strpos($fileLinkFormat, '#', $i) ?: strlen($fileLinkFormat);
47+
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
48+
parse_str($fileLinkFormat[1], $fileLinkFormat[1]);
49+
}
4350
$this->stopwatch = $stopwatch;
44-
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
51+
$this->fileLinkFormat = $fileLinkFormat;
4552
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
4653
$this->requestStack = $requestStack;
4754
$this->dumper = $dumper;
@@ -149,6 +156,7 @@ public function collect(Request $request, Response $response, \Exception $except
149156
) {
150157
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
151158
$this->dumper = new HtmlDumper('php://output', $this->charset);
159+
$this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
152160
} else {
153161
$this->dumper = new CliDumper('php://output', $this->charset);
154162
}
@@ -198,6 +206,7 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
198206

199207
if ('html' === $format) {
200208
$dumper = new HtmlDumper($data, $this->charset);
209+
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
201210
} else {
202211
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
203212
}
@@ -234,6 +243,7 @@ public function __destruct()
234243

235244
if ('cli' !== PHP_SAPI && stripos($h[$i], 'html')) {
236245
$this->dumper = new HtmlDumper('php://output', $this->charset);
246+
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
237247
} else {
238248
$this->dumper = new CliDumper('php://output', $this->charset);
239249
}
@@ -258,7 +268,13 @@ private function doDump($data, $name, $file, $line)
258268
$name = strip_tags($this->style('', $name));
259269
$file = strip_tags($this->style('', $file));
260270
if ($fileLinkFormat) {
261-
$link = strtr(strip_tags($this->style('', $fileLinkFormat)), array('%f' => $file, '%l' => (int) $line));
271+
foreach ($fileLinkFormat[1] as $k => $v) {
272+
if (0 === strpos($file, $k)) {
273+
$file = substr_replace($file, $v, 0, strlen($k));
274+
break;
275+
}
276+
}
277+
$link = strtr(strip_tags($this->style('', $fileLinkFormat[0])), array('%f' => $file, '%l' => (int) $line));
262278
$name = sprintf('<a href="%s" title="%s">'.$s.'</a>', $link, $file, $name);
263279
} else {
264280
$name = sprintf('<abbr title="%s">'.$s.'</abbr>', $file, $name);

EventListener/DebugHandlersListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DebugHandlersListener implements EventSubscriberInterface
4444
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
4545
* @param int|null $throwAt Thrown errors in a bit field of E_* constants, or null to keep the current value
4646
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
47-
* @param string $fileLinkFormat The format for links to source files
47+
* @param string|array $fileLinkFormat The format for links to source files
4848
* @param bool $scope Enables/disables scoping mode
4949
*/
5050
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, $throwAt = E_ALL, $scream = true, $fileLinkFormat = null, $scope = true)
@@ -54,7 +54,7 @@ public function __construct(callable $exceptionHandler = null, LoggerInterface $
5454
$this->levels = null === $levels ? E_ALL : $levels;
5555
$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? E_ALL : null));
5656
$this->scream = (bool) $scream;
57-
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
57+
$this->fileLinkFormat = $fileLinkFormat;
5858
$this->scope = (bool) $scope;
5959
}
6060

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"symfony/stopwatch": "~2.8|~3.0",
3838
"symfony/templating": "~2.8|~3.0",
3939
"symfony/translation": "~2.8|~3.0",
40-
"symfony/var-dumper": "~2.8|~3.0"
40+
"symfony/var-dumper": "~3.2"
4141
},
4242
"conflict": {
4343
"symfony/config": "<2.8"

0 commit comments

Comments
 (0)