10000 Merge branch '3.4' into 4.0 · symfony/symfony@f76624a · GitHub
[go: up one dir, main page]

Skip to content

Commit f76624a

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: fixed tests [Finder] Remove duplicate slashes in filenames [VarDumper] Skip some tests on custom xdebug.file_link_format [WebProfilerBundle][HttpKernel] Make FileLinkFormatter URL format generation lazy bumped Symfony version to 3.4.8 updated VERSION for 3.4.7 updated CHANGELOG for 3.4.7
2 parents b74ae40 + c362622 commit f76624a

File tree

8 files changed

+93
-25
lines changed

8 files changed

+93
-25
lines changed

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1415
use Symfony\Component\DependencyInjection\Extension\Extension;
1516
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Reference;
1719
use Symfony\Component\Config\FileLocator;
20+
use Symfony\Component\HttpKernel\Kernel;
1821
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
1922

2023
/**
@@ -51,6 +54,11 @@ public function load(array $configs, ContainerBuilder $container)
5154
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
5255
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
5356
}
57+
58+
if (Kernel::VERSION_ID >= 30408 || Kernel::VERSION_ID >= 40008) {
59+
$container->getDefinition('debug.file_link_formatter')
60+
->replaceArgument(3, new ServiceClosureArgument(new Reference('debug.file_link_formatter.url_format')));
61+
}
5462
}
5563

5664
/**

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,14 @@
5555
<argument>%debug.file_link_format%</argument>
5656
<argument type="service" id="request_stack" on-invalid="ignore" />
5757
<argument>%kernel.project_dir%</argument>
58-
<argument type="service">
59-
<service class="string">
60-
<factory function="implode" />
61-
<argument type="collection">
62-
<argument type="service">
63-
<service class="string">
64-
<factory service="router" method="generate" />
65-
<argument>_profiler_open_file</argument>
66-
</service>
67-
</argument>
68-
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
69-
</argument>
70-
</service>
71-
</argument>
58+
<argument>/_profiler/open?file=%%f&amp;line=%%l#line%%l</argument>
59+
</service>
60+
61+
<service id="debug.file_link_formatter.url_format" class="string">
62+
<factory class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" method="generateUrlFormat" />
63+
<argument type="service" id="router" />
64+
<argument>_profiler_open_file</argument>
65+
<argument>?file=%%f&amp;line=%%l#line%%l</argument>
7266
</service>
7367
</services>
7468
</container>

src/Symfony/Component/Finder/Finder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ public function in($dirs)
540540

541541
foreach ((array) $dirs as $dir) {
542542
if (is_dir($dir)) {
543-
$resolvedDirs[] = $dir;
543+
$resolvedDirs[] = $this->normalizeDir($dir);
544544
} elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
545-
$resolvedDirs = array_merge($resolvedDirs, $glob);
545+
$resolvedDirs = array_merge($resolvedDirs, array_map(array($this, 'normalizeDir'), $glob));
546546
} else {
547547
throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
548548
}
@@ -723,4 +723,16 @@ private function searchInDirectory(string $dir): \Iterator
723723

724724
return $iterator;
725725
}
726+
727+
/**
728+
* Normalizes given directory names by removing trailing slashes.
729+
*
730+
* @param string $dir
731+
*
732+
* @return string
733+
*/
734+
private function normalizeDir($dir)
735+
{
736+
return rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
737+
}
726738
}

src/Symfony/Component/Finder/SplFileInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SplFileInfo extends \SplFileInfo
2828
*/
2929
public function __construct(string $file, string $relativePath, string $relativePathname)
3030
{
31-
parent::__construct(realpath($file) ?: $file);
31+
parent::__construct($file);
3232
$this->relativePath = $relativePath;
3333
$this->relativePathname = $relativePathname;
3434
}

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,40 @@ public function testFiles()
4848

4949
public function testRemoveTrailingSlash()
5050
{
51-
if ('\\' === \DIRECTORY_SEPARATOR) {
52-
$this->markTestSkipped('This test cannot be run on Windows.');
51+
$finder = $this->buildFinder();
52+
53+
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
54+
$in = self::$tmpDir.'//';
55+
56+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
57+
}
58+
59+
public function testSymlinksNotResolved()
60+
{
61+
if ('\\' === DIRECTORY_SEPARATOR) {
62+
$this->markTestSkipped('symlinks are not supported on Windows');
5363
}
5464

5565
$finder = $this->buildFinder();
5666

57-
$expected = $this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar'));
58-
$in = '//'.realpath(self::$tmpDir).'//';
67+
symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
68+
$expected = $this->toAbsolute(array('baz/bar.tmp'));
69+
$in = self::$tmpDir.'/baz/';
70+
try {
71+
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
72+
unlink($this->toAbsolute('baz'));
73+
} catch (\Exception $e) {
74+
unlink($this->toAbsolute('baz'));
75+
throw $e;
76+
}
77+
}
78+
79+
public function testBackPathNotNormalized()
80+
{
81+
$finder = $this->buildFinder();
5982

83+
$expected = $this->toAbsolute(array('foo/../foo/bar.tmp'));
84+
$in = self::$tmpDir.'/foo/../foo/';
6085
$this->assertIterator($expected, $finder->in($in)->files()->getIterator());
6186
}
6287

@@ -275,7 +300,7 @@ public function testInWithNonExistentDirectory()
275300
public function testInWithGlob()
276301
{
277302
$finder = $this->buildFinder();
278-
$finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator();
303+
$finder->in(array(__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'))->getIterator();
279304

280305
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
281306
}
@@ -528,8 +553,8 @@ public function testMultipleLocationsWithSubDirectories()
528553
$finder->in($locations)->depth('< 10')->name('*.neon');
529554

530555
$expected = array(
531-
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
532-
__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
556+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
557+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
533558
);
534559

535560
$this->assertIterator($expected, $finder);

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\RequestStack;
16+
use Symfony\Component\Routing\Exception\ExceptionInterface;
17+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1618

1719
/**
1820
* Formats debug file links.
@@ -26,7 +28,10 @@ class FileLinkFormatter implements \Serializable
2628
private $baseDir;
2729
private $urlFormat;
2830

29-
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string $urlFormat = null)
31+
/**
32+
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
33+
*/
34+
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
3035
{
3136
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3237
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
@@ -66,6 +71,18 @@ public function unserialize($serialized)
6671
$this->fileLinkFormat = unserialize($serialized, array('allowed_classes' => false));
6772
}
6873

74+
/**
75+
* @internal
76+
*/
77+
public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString)
78+
{
79+
try {
80+
return $router->generate($routeName).$queryString;
81+
} catch (ExceptionInterface $e) {
82+
return null;
83+
}
84+
}
85+
6986
private function getFileLinkFormat()
7087
{
7188
if ($this->fileLinkFormat) {
@@ -74,6 +91,10 @@ private function getFileLinkFormat()
7491
if ($this->requestStack && $this->baseDir && $this->urlFormat) {
7592
$request = $this->requestStack->getMasterRequest();
7693
if ($request instanceof Request) {
94+
if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) {
95+
return;
96+
}
97+
7798
return array(
7899
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
79100
$this->baseDir.DIRECTORY_SEPARATOR, '',

src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public function testNoSrcContext()
126126

127127
public function testHtmlDump()
128128
{
129+
if (ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) {
130+
$this->markTestSkipped('A custom file_link_format is defined.');
131+
}
132+
129133
$e = $this->getTestException(1);
130134
ExceptionCaster::$srcContext = -1;
131135

src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class HtmlDumperTest extends TestCase
2222
{
2323
public function testGet()
2424
{
25+
if (ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) {
26+
$this->markTestSkipped('A custom file_link_format is defined.');
27+
}
28+
2529
require __DIR__.'/../Fixtures/dumb-var.php';
2630

2731
$dumper = new HtmlDumper('php://output');

0 commit comments

Comments
 (0)
0