Skip to content

Commit 34e5613

Browse files
committed
bug symfony#20336 [HttpKernel] Base DataCollector throws warning on unsupported scheme strings (ogizanagi)
This PR was merged into the 3.2-dev branch. Discussion ---------- [HttpKernel] Base DataCollector throws warning on unsupported scheme strings | Q | A | | --- | --- | | Branch? | master | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | N/A | | License | MIT | | Doc PR | N/A | The issue concerns any collector based on the abstract `Symfony\Component\HttpKernel\DataCollector\DataCollector` class using `cloneVar` on a string containing a unsupported scheme. The easiest way to reproduce the issue is to add a simple query parameter like `?uri=foo://bar` on any url of your application: > ContextErrorException in DataCollector.php line 134: > Warning: file_exists(): Unable to find the wrapper "foo" - did you forget to enable it when you configured PHP? This PR simply fixes the issue by muting the warning on `file_exists`. But maybe there is a better strategy. Commits ------- 52faa00 Fix base DataCollector throws warning on unsupported scheme strings
2 parents 070e53a + 52faa00 commit 34e5613

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function decorateVar($var)
130130
return new ClassStub($var);
131131
}
132132
}
133-
if (false !== strpos($var, DIRECTORY_SEPARATOR) && file_exists($var)) {
133+
if (false !== strpos($var, DIRECTORY_SEPARATOR) && false === strpos($var, '://') && file_exists($var)) {
134134
return new LinkStub($var);
135135
}
136136
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\CloneVarDataCollector;
17+
use Symfony\Component\VarDumper\Cloner\Stub;
18+
use Symfony\Component\VarDumper\Cloner\VarCloner;
19+
use Symfony\Component\VarDumper\Dumper\CliDumper;
20+
21+
class DataCollectorTest extends \PHPUnit_Framework_TestCase
22+
{
23+
public function testCloneVarStringWithScheme()
24+
{
25+
$c = new CloneVarDataCollector('scheme://foo');
26+
$c->collect(new Request(), new Response());
27+
$cloner = new VarCloner();
28+
29+
$this->assertEquals($cloner->cloneVar('scheme://foo'), $c->getData());
30+
}
31+
32+
public function testCloneVarExistingFilePath()
33+
{
34+
$c = new CloneVarDataCollector($filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_'));
35+
$c->collect(new Request(), new Response());
36+
37+
$data = $c->getData();
38+
$this->assertInstanceOf(Stub::class, $data->getRawData()[0][0]);
39+
$this->assertDumpEquals("\"$filePath\"", $data);
40+
}
41+
42+
private function assertDumpEquals($dump, $data, $message = '')
43+
{
44+
$dumper = new CliDumper();
45+
$dumper->setColors(false);
46+
47+
$this->assertSame(rtrim($dump), rtrim($dumper->dump($data, true)), $message);
48+
}
49+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
17+
18+
class CloneVarDataCollector extends DataCollector
19+
{
20+
private $varToClone;
21+
22+
public function __construct($varToClone)
23+
{
24+
$this->varToClone = $varToClone;
25+
}
26+
27+
public function collect(Request $request, Response $response, \Exception $exception = null)
28+
{
29+
$this->data = $this->cloneVar($this->varToClone);
30+
}
31+
32+
public function getData()
33+
{
34+
return $this->data;
35+
}
36+
37+
public function getName()
38+
{
39+
return 'clone_var';
40+
}
41+
}

0 commit comments

Comments
 (0)