Skip to content

Simplified link-to-source mapping definitions in debug.file_link_format #20101

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
Oct 5, 2016
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
12 changes: 5 additions & 7 deletions src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}
$this->fileLinkFormat = $fileLinkFormat;
$this->rootDir = str_replace('/', DIRECTORY_SEPARATOR, dirname($rootDir)).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -198,9 +196,9 @@ public function formatFile($file, $line, $text = null)
public function getFileLink($file, $line)
{
if ($this->fileLinkFormat && file_exists($file)) {
foreach ($this->fileLinkFormat[1] as $k => $v) {
if (0 === strpos($file, $k)) {
$file = substr_replace($file, $v, 0, strlen($k));
for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) {
if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) {
$file = substr_replace($file, $this->fileLinkFormat[$i], 0, strlen($k));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function testGetName()

protected function getExtension()
{
return new CodeExtension('proto://%f#&line=%l#'.json_encode(substr(__FILE__, 0, 5)).':"foobar"', '/root', 'UTF-8');
return new CodeExtension('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar', '/root', 'UTF-8');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}
$this->fileLinkFormat = $fileLinkFormat;
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
Expand Down Expand Up @@ -193,9 +191,9 @@ public function formatFile($file, $line, $text = null)
public function getFileLink($file, $line)
{
if ($this->fileLinkFormat && is_file($file)) {
foreach ($this->fileLinkFormat[1] as $k => $v) {
if (0 === strpos($file, $k)) {
$file = substr_replace($file, $v, 0, strlen($k));
for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) {
if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) {
$file = substr_replace($path, $this->fileLinkFormat[$i], 0, strlen($k));
break;
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/Symfony/Component/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public function __construct($debug = true, $charset = null, $fileLinkFormat = nu
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}
$this->debug = $debug;
$this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8';
Expand Down Expand Up @@ -97,9 +95,8 @@ public function setFileLinkFormat($fileLinkFormat)
{
$old = $this->fileLinkFormat;
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
$i = strpos($fileLinkFormat, '#"') ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}
$this->fileLinkFormat = $fileLinkFormat;
if ($old) {
Expand Down Expand Up @@ -368,9 +365,9 @@ private function formatPath($path, $line)
$file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path);

if ($fileLinkFormat = $this->fileLinkFormat) {
foreach ($fileLinkFormat[1] as $k => $v) {
if (0 === strpos($path, $k)) {
$path = substr_replace($path, $v, 0, strlen($k));
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
if (0 === strpos($path, $k = $fileLinkFormat[$i++])) {
$path = substr_replace($path, $fileLinkFormat[$i], 0, strlen($k));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null,
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}
$this->stopwatch = $stopwatch;
$this->fileLinkFormat = $fileLinkFormat;
Expand Down Expand Up @@ -268,9 +266,9 @@ private function doDump($data, $name, $file, $line)
$name = strip_tags($this->style('', $name));
$file = strip_tags($this->style('', $file));
if ($fileLinkFormat) {
foreach ($fileLinkFormat[1] as $k => $v) {
if (0 === strpos($file, $k)) {
$file = substr_replace($file, $v, 0, strlen($k));
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
if (0 === strpos($file, $k = $fileLinkFormat[$i++])) {
$file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k));
break;
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,12 @@ private function getSourceLink($file, $line)
return false;
}
if (!is_array($fileLinkFormat)) {
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
$this->extraDisplayOptions['fileLinkFormat'] = $fileLinkFormat;
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
}

foreach ($fileLinkFormat[1] as $k => $v) {
if (0 === strpos($file, $k)) {
$file = substr_replace($file, $v, 0, strlen($k));
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
if (0 === strpos($file, $k = $fileLinkFormat[$i++])) {
$file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k));
break;
}
}
Expand Down