Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d12c0f

Browse files
[VarDumper] Add SymfonyCaster::castRequest()
1 parent 51bc35c commit 5d12c0f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\VarDumper\Caster;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\VarDumper\Cloner\Stub;
16+
17+
class SymfonyCaster
18+
{
19+
private static $getters = array(
20+
'pathInfo' => 'getPathInfo',
21+
'requestUri' => 'getRequestUri',
22+
'baseUrl' => 'getBaseUrl',
23+
'basePath' => 'getBasePath',
24+
'method' => 'getMethod',
25+
'format' => 'getRequestFormat',
26+
);
27+
28+
public static function castRequest(Request $request, array $a, Stub $stub, $isNested)
29+
{
30+
$clone = null;
31+
32+
foreach (self::$getters as $prop => $getter) {
33+
if (null === $a["\0*\0$prop"]) {
34+
if (null === $clone) {
35+
$clone = clone $request;
36+
}
37+
$a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
38+
}
39+
}
40+
41+
return $a;
42+
}
43+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ abstract class AbstractCloner implements ClonerInterface
7575
'Exception' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castException',
7676
'Error' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castError',
7777
'Symfony\Component\DependencyInjection\ContainerInterface' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
78+
'Symfony\Component\HttpFoundation\Request' => 'Symfony\Component\VarDumper\Caster\SymfonyCaster::castRequest',
7879
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castThrowingCasterException',
7980
'Symfony\Component\VarDumper\Caster\TraceStub' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castTraceStub',
8081
'Symfony\Component\VarDumper\Caster\FrameStub' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castFrameStub',

0 commit comments

Comments
 (0)