8000 minor #20101 Simplified link-to-source mapping definitions in debug.f… · symfony/symfony@63308cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 63308cd

Browse files
committed
minor #20101 Simplified link-to-source mapping definitions in debug.file_link_format (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- Simplified link-to-source mapping definitions in debug.file_link_format | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19950 | License | MIT | Doc PR | symfony/symfony-docs#7019 Having to json_encode here (or any other kind of encoding) is really tedious to deal with: it makes it hard to have things working quickly. `%f` and `%l` aren't encoded anyway, so let's use very unlikely chars as separators here also instead. Commits ------- 27df38e Simplified link-to-source mapping definitions in debug.file_link_format
2 parents 3ad5b29 + 27df38e commit 63308cd

File tree

6 files changed

+28
-41
lines changed

6 files changed

+28
-41
lines changed

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
3333
{
3434
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3535
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
36-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
37-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
38-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
39-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
36+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
37+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
4038
}
4139
$this->fileLinkFormat = $fileLinkFormat;
4240
$this->rootDir = str_replace('/', DIRECTORY_SEPARATOR, dirname($rootDir)).DIRECTORY_SEPARATOR;
@@ -198,9 +196,9 @@ public function formatFile($file, $line, $text = null)
198196
public function getFileLink($file, $line)
199197
{
200198
if ($this->fileLinkFormat && file_exists($file)) {
201-
foreach ($this->fileLinkFormat[1] as $k => $v) {
202-
if (0 === strpos($file, $k)) {
203-
$file = substr_replace($file, $v, 0, strlen($k));
199+
for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) {
200+
if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) {
201+
$file = substr_replace($file, $this->fileLinkFormat[$i], 0, strlen($k));
204202
break;
205203
}
206204
}

src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public function testGetName()
6464

6565
protected function getExtension()
6666
{
67-
return new CodeExtension('proto://%f#&line=%l#'.json_encode(substr(__FILE__, 0, 5)).':"foobar"', '/root', 'UTF-8');
67+
return new CodeExtension('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar', '/root', 'UTF-8');
6868
}
6969
}

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
3535
{
3636
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3737
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
38-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
39-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
40-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
41-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
38+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
39+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
4240
}
4341
$this->fileLinkFormat = $fileLinkFormat;
4442
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
@@ -193,9 +191,9 @@ public function formatFile($file, $line, $text = null)
193191
public function getFileLink($file, $line)
194192
{
195193
if ($this->fileLinkFormat && is_file($file)) {
196-
foreach ($this->fileLinkFormat[1] as $k => $v) {
197-
if (0 === strpos($file, $k)) {
198-
$file = substr_replace($file, $v, 0, strlen($k));
194+
for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) {
195+
if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) {
196+
$file = substr_replace($path, $this->fileLinkFormat[$i], 0, strlen($k));
199197
break;
200198
}
201199
}

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public function __construct($debug = true, $charset = null, $fileLinkFormat = nu
3939
{
4040
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4141
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
42-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
43-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
44-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
45-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
42+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
43+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
4644
}
4745
$this->debug = $debug;
4846
$this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8';
@@ -97,9 +95,8 @@ public function setFileLinkFormat($fileLinkFormat)
9795
{
9896
$old = $this->fileLinkFormat;
9997
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
100-
$i = strpos($fileLinkFormat, '#"') ?: strlen($fileLinkFormat);
101-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
102-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
98+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
99+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
103100
}
104101
$this->fileLinkFormat = $fileLinkFormat;
105102
if ($old) {
@@ -368,9 +365,9 @@ private function formatPath($path, $line)
368365
$file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path);
369366

370367
if ($fileLinkFormat = $this->fileLinkFormat) {
371-
foreach ($fileLinkFormat[1] as $k => $v) {
372-
if (0 === strpos($path, $k)) {
373-
$path = substr_replace($path, $v, 0, strlen($k));
368+
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
369+
if (0 === strpos($path, $k = $fileLinkFormat[$i++])) {
370+
$path = substr_replace($path, $fileLinkFormat[$i], 0, strlen($k));
374371
break;
375372
}
376373
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null,
4242
{
4343
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4444
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-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
45+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
46+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
4947
}
5048
$this->stopwatch = $stopwatch;
5149
$this->fileLinkFormat = $fileLinkFormat;
@@ -268,9 +266,9 @@ private function doDump($data, $name, $file, $line)
268266
$name = strip_tags($this->style('', $name));
269267
$file = strip_tags($this->style('', $file));
270268
if ($fileLinkFormat) {
271-
foreach ($fileLinkFormat[1] as $k => $v) {
272-
if (0 === strpos($file, $k)) {
273-
$file = substr_replace($file, $v, 0, strlen($k));
269+
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
270+
if (0 === strpos($file, $k = $fileLinkFormat[$i++])) {
271+
$file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k));
274272
break;
275273
}
276274
}

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,12 @@ private function getSourceLink($file, $line)
542542
return false;
543543
}
544544
if (!is_array($fileLinkFormat)) {
545-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
546-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
547-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
548-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
549-
$this->extraDisplayOptions['fileLinkFormat'] = $fileLinkFormat;
545+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
546+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
550547
}
551-
552-
foreach ($fileLinkFormat[1] as $k => $v) {
553-
if (0 === strpos($file, $k)) {
554-
$file = substr_replace($file, $v, 0, strlen($k));
548+
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
549+
if (0 === strpos($file, $k = $fileLinkFormat[$i++])) {
550+
$file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k));
555551
break;
556552
}
557553
}

0 commit comments

Comments
 (0)
0