8000 [VarDumper] Added support for SplFileInfo · symfony/symfony@9cb5743 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cb5743

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

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
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\Var 43F0 Dumper\Caster\SplCaster::castFixedArray',
8283
'SplHeap' => 'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
8384
'SplObjectStorage' => 'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',

0 commit comments

Comments
 (0)
0