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

Skip to content

Commit eb50b13

Browse files
committed
[VarDumper] Added support for SplFileInfo
1 parent 862bdf1 commit eb50b13

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,56 @@ public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, S
7272
return $a;
7373
}
7474

75+
public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNested)
76+
{
77+
static $map = array(
78+
'path' => 'getPath',
79+
'filename' => 'getFilename',
80+
'basename' => 'getBasename',
81+
'pathname' => 'getPathname',
82+
'extension' => 'getExtension',
83+
'realPath' => 'getRealPath',
84+
'aTime' => 'getATime',
85+
'mTime' => 'getMTime',
86+
'cTime' => 'getCTime',
87+
'inode' => 'getInode',
88+
'size' => 'getSize',
89+
'perms' => 'getPerms',
90+
'owner' => 'getOwner',
91+
'group' => 'getGroup',
92+
'type' => 'getType',
93+
'writable' => 'isWritable',
94+
'readable' => 'isReadable',
95+
'executable' => 'isExecutable',
96+
'file' => 'isFile',
97+
'dir' => 'isDir',
98+
'link' => 'isLink',
99+
'linkTarget' => 'getLinkTarget',
100+
);
101+
102+
$prefix = Caster::PREFIX_VIRTUAL;
103+
104+
foreach ($map as $key => $accessor) {
105+
try {
106+
$a[$prefix.$key] = $c->$accessor();
107+
} catch (\Exception $e) {
108+
}
109+
}
110+
111+
if (isset($a[$prefix.'perms'])) {
112+
$a[$prefix.'perms'] = new ConstStub(sprintf('0%o', $a[$prefix.'perms']), $a[$prefix.'perms']);
113+
}
114+
115+
static $mapDate = array('aTime', 'mTime', 'cTime');
116+
foreach ($mapDate as $key) {
117+
if (isset($a[$prefix.$key])) {
118+
$a[$prefix.$key] = new ConstStub(date('Y-m-d H:i:s', $a[$prefix.$key]), $a[$prefix.$key]);
119+
}
120+
}
121+
122+
return $a;
123+
}
124+
75125
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
76126
{
77127
$a += array(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ abstract class AbstractCloner implements ClonerInterface
7878

7979
'ArrayObject' => 'Symfony\Component\VarDumper\Caster\SplCaster::castArrayObject',
8080
'SplDoublyLinkedList' => 'Symfony\Component\VarDumper\Caster\SplCaster::castDoublyLinkedList',
81+
'SplFileInfo' => 'Symfony\Component\VarDumper\Caster\SplCaster::castFileInfo',
8182
'SplFixedArray' => 'Symfony\Component\VarDumper\Caster\SplCaster::castFixedArray',
8283
'SplHeap' => 'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
8384
'SplObjectStorage' => 'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',

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

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

1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

14-
use Symfony\Component\VarDumper\Cloner\VarCloner;
15-
use Symfony\Component\VarDumper\Dumper\CliDumper;
1614
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
1715

1816
/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Tests\Caster;
13+
14+
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
15+
16+
/**
17+
* @author Grégoire Pineau <[email protected]>
18+
*/
19+
class SplCasterTest extends VarDumperTestCase
20+
{
21+
public function getCastFileInfoTests()
22+
{
23+
return array(
24+
array(__FILE__, <<<'EOTXT'
25+
SplFileInfo {
26+
path: "%s/src/Symfony/Component/VarDumper/Tests/Caster"
27+
filename: "SplCasterTest.php"
28+
basename: "SplCasterTest.php"
29+
pathname: "%s/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php"
30+
extension: "php"
31+
realPath: "%s/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php"
32+
aTime: %s-%s-%d %d:%d:%d
33+
mTime: %s-%s-%d %d:%d:%d
34+
cTime: %s-%s-%d %d:%d:%d
35+
inode: %d
36+
size: %d
37+
perms: 0100644
38+
owner: 1000
39+
group: 1000
40+
type: "file"
41+
writable: true
42+
readable: true
43+
executable: false
44+
file: true
45+
dir: false
46+
link: false
47+
}
48+
EOTXT
49+
),
50+
array('https://google.com/about', <<<'EOTXT'
51+
SplFileInfo {
52+
path: "https://google.com"
53+
filename: "about"
54+
basename: "about"
55+
pathname: "https://google.com/about"
56+
extension: ""
57+
realPath: false
58+
writable: false
59+
readable: false
60+
executable: false
61+
file: false
62+
dir: false
63+
link: false
64+
}
65+
EOTXT
66+
),
67+
);
68+
}
69+
70+
/** @dataProvider getCastFileInfoTests */
71+
public function testCastFileInfo($file, $dump)
72+
{
73+
$this->assertDumpMatchesFormat($dump, new \SplFileInfo($file));
74+
}
75+
}

0 commit comments

Comments
 (0)