8000 Added back the RequestStack-based code · symfony/symfony@b54054d · GitHub
[go: up one dir, main page]

Skip to content

Commit b54054d

Browse files
committed
Added back the RequestStack-based code
1 parent b7ea19b commit b54054d

File tree

3 files changed

+32
-8
lines changed
  • src/Symfony
    • Bundle/WebProfilerBundle/Resources/config
    • Component/HttpKernel
      • Debug
      • Tests/Debug

3 files changed

+32
-8
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter">
5656
<argument>%debug.file_link_format%</argument>
57-
<argument>null</argument> <!-- unused, to be removed in Symfony 4.0 -->
57+
<argument type="service" id="request_stack" on-invalid="ignore" />
5858
<argument>null</argument>
5959
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
6060
<argument type="service" id="router" on-invalid="null" />

src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@
2222
class FileLinkFormatter implements \Serializable
2323
{
2424
private $fileLinkFormat;
25+
private $requestStack;
2526
private $router;
2627
private $baseDir;
2728
private $queryString;
2829

2930
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $queryString = null, UrlGeneratorInterface $router = null)
3031
{
31-
// TODO: '$requestStack' constructor argument is unused. Remove it in Symfony 4.0.
3232
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3333
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
3434
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
3535
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
3636
}
3737

3838
$this->fileLinkFormat = $fileLinkFormat;
39+
$this->requestStack = $requestStack;
3940
$this->router = $router;
4041
$this->baseDir = $baseDir;
4142
$this->queryString = $queryString;
@@ -77,13 +78,21 @@ private function getFileLinkFormat()
7778
return $this->fileLinkFormat;
7879
}
7980

80-
if (null === $this->router) {
81-
return;
81+
if (null !== $this->router) {
82+
return array(
83+
$this->router->generate('_profiler_open_file').$this->queryString,
84+
$this->baseDir.DIRECTORY_SEPARATOR, '',
85+
);
8286
}
8387

84-
return array(
85-
$this->router->generate('_profiler_open_file').$this->queryString,
86-
$this->baseDir.DIRECTORY_SEPARATOR, '',
87-
);
88+
if (null !== $this->requestStack) {
89+
$request = $this->requestStack->getMasterRequest();
90+
if ($request instanceof Request) {
91+
return array(
92+
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
93+
$this->baseDir.DIRECTORY_SEPARATOR, '',
94+
);
95+
}
96+
}
8897
}
8998
}

src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\HttpKernel\Tests\Debug;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\RequestStack;
1517
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1618
use Symfony\Component\Routing\Generator\UrlGenerator;
1719
use Symfony\Component\Routing\RequestContext;
@@ -36,6 +38,19 @@ public function testWhenFileLinkFormat()
3638
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
3739
}
3840

41+
public function testWhenFileLinkFormatAndRequestStack()
42+
{
43+
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
44+
$baseDir = __DIR__;
45+
$requestStack = new RequestStack();
46+
$request = new Request();
47+
$requestStack->push($request);
48+
49+
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
50+
51+
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
52+
}
53+
3954
public function testWhenFileLinkFormatAndRouter()
4055
{
4156
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';

0 commit comments

Comments
 (0)
0