8000 Use the router to resolve the file links in the profiler by javiereguiluz · Pull Request #24153 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Use the router to resolve the file links in the profiler #24153

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
added proper deprecation notices
  • Loading branch information
fabpot committed Oct 1, 2017
commit ebbab3b1e2b9b2ad77ac2ac8c9ff594884490051
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@

<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter">
<argument>%debug.file_link_format%</argument>
<argument type="service" id="request_stack" on-invalid="ignore" />
<argument type="service" id="router" on-invalid="null" />
<argument>null</argument>
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
<argument type="service" id="router" on-invalid="null" />
</service>
</services>
</container>
22 changes: 16 additions & 6 deletions src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ class FileLinkFormatter implements \Serializable
{
private $fileLinkFormat;
private $requestStack;
private $router;
private $urlGenerator;
private $baseDir;
private $queryString;

public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $queryString = null, UrlGeneratorInterface $router = null)
/**
* @param $urlGenerator UrlGeneratorInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param UrlGeneratorInterface $urlGenerator

*/
public function __construct($fileLinkFormat = null, $urlGenerator = null, $baseDir = null, $queryString = null)
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
Expand All @@ -36,10 +39,17 @@ public function __construct($fileLinkFormat = null, RequestStack $requestStack =
}

$this->fileLinkFormat = $fileLinkFormat;
$this->requestStack = $requestStack;
$this->router = $router;
$this->baseDir = $baseDir;
$this->queryString = $queryString;

if ($urlGenerator instanceof RequestStack) {
@trigger_error(sprintf('Passing a RequestStack to %s() as a second argument is deprecated since version 3.4 and will be unsupported in 4.0. Pass a UrlGeneratorInterface instead.', __METHOD__), E_USER_DEPRECATED);
$this->requestStack = $urlGenerator;
} elseif ($urlGenerator instanceof UrlGeneratorInterface) {
$this->urlGenerator = $urlGenerator;
} elseif (null !== $urlGenerator) {
throw new \InvalidArgumentException('The second argument of %s() must either implement UrlGeneratorInterface or RequestStack.');
}
}

public function format($file, $line)
Expand Down Expand Up @@ -78,9 +88,9 @@ private function getFileLinkFormat()
return $this->fileLinkFormat;
}

if (null !== $this->router) {
if (null !== $this->urlGenerator) {
return array(
$this->router->generate('_profiler_open_file').$this->queryString,
$this->urlGenerator->generate('_profiler_open_file').$this->queryString,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ties it to the definition of WebProfilerBundle. I suggest that we make it configurable instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please do that in the future in case enough people ask for it?

$this->baseDir.DIRECTORY_SEPARATOR, '',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function testWhenFileLinkFormat()
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
}

/**
* @group legacy
*/
public function testWhenFileLinkFormatAndRequestStack()
{
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
Expand All @@ -55,9 +58,8 @@ public function testWhenFileLinkFormatAndRouter()
{
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
$baseDir = __DIR__;
$router = $this->getRouter();

$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', null, $baseDir, '/_profiler/open?file=%f&line=%l#line%l', $router);
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $this->getUrlGenerator(), $baseDir, '/_profiler/open?file=%f&line=%l#line%l');

$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
}
Expand All @@ -66,14 +68,13 @@ public function testWhenNoFileLinkFormatAndRouter()
{
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
$baseDir = __DIR__;
$router = $this->getRouter();

$sut = new FileLinkFormatter(null, null, $baseDir, '?file=%f&line=%l#line%l', $router);
$sut = new FileLinkFormatter(null, $this->getUrlGenerator(), $baseDir, '?file=%f&line=%l#line%l');

$this->assertSame('/_profiler_customized?file=file.php&line=3#line3', $sut->format($file, 3));
}

private function getRouter()
private function getUrlGenerator()
{
$routes = new RouteCollection();
$routes->add('_profiler_open_file', new Route('/_profiler_customized'));
Expand Down
0