8000 added proper deprecation notices · symfony/symfony@f659954 · GitHub
[go: up one dir, main page]

Skip to content

Commit f659954

Browse files
committed
added proper deprecation notices
1 parent 46cb297 commit f659954

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ class FileLinkFormatter implements \Serializable
2323
{
2424
private $fileLinkFormat;
2525
private $requestStack;
26-
private $router;
26+
private $urlGenerator;
2727
private $baseDir;
2828
private $queryString;
2929

30-
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $queryString = null, UrlGeneratorInterface $router = null)
30+
/**
31+
* @param $urlGenerator UrlGeneratorInterface
32+
*/
33+
public function __construct($fileLinkFormat = null, $urlGenerator = null, $baseDir = null, $queryString = null)
3134
{
3235
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3336
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
@@ -36,10 +39,17 @@ public function __construct($fileLinkFormat = null, RequestStack $requestStack =
3639
}
3740

3841
$this->fileLinkFormat = $fileLinkFormat;
39-
$this->requestStack = $requestStack;
40-
$this->router = $router;
4142
$this->baseDir = $baseDir;
4243
$this->queryString = $queryString;
44+
45+
if ($urlGenerator instanceof RequestStack) {
46+
@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);
47+
$this->requestStack = $urlGenerator;
48+
} elseif ($urlGenerator instanceof UrlGeneratorInterface) {
49+
$this->urlGenerator = $urlGenerator;
50+
} elseif (null !== $urlGenerator) {
51+
throw new \InvalidArgumentException('The second argument of %s() must either implement UrlGeneratorInterface or RequestStack.');
52+
}
4353
}
4454

4555
public function format($file, $line)
@@ -78,9 +88,9 @@ private function getFileLinkFormat()
7888
return $this->fileLinkFormat;
7989
}
8090

81-
if (null !== $this->router) {
91+
if (null !== $this->urlGenerator) {
8292
return array(
83-
$this->router->generate('_profiler_open_file').$this->queryString,
93+
$this->urlGenerator->generate('_profiler_open_file').$this->queryString,
8494
$this->baseDir.DIRECTORY_SEPARATOR, '',
8595
);
8696
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function testWhenFileLinkFormat()
3838
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
3939
}
4040

41+
/**
42+
* @group legacy
43+
*/
4144
public function testWhenFileLinkFormatAndRequestStack()
4245
{
4346
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
@@ -55,9 +58,8 @@ public function testWhenFileLinkFormatAndRouter()
5558
{
5659
$file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
5760
$baseDir = __DIR__;
58-
$router = $this->getRouter();
5961

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

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

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

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

76-
private function getRouter()
77+
private function getUrlGenerator()
7778
{
7879
$routes = new RouteCollection();
7980
$routes->add('_profiler_open_file', new Route('/_profiler_customized'));

0 commit comments

Comments
 (0)
0