Skip to content

Commit 3783f52

Browse files
committed
[VarDumper] Added support for SplFileObject
1 parent 9cb5743 commit 3783f52

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
*/
2121
class SplCaster
2222
{
23+
private static $splFileObjectFlags = array(
24+
\SplFileObject::DROP_NEW_LINE => 'DROP_NEW_LINE',
25+
\SplFileObject::READ_AHEAD => 'READ_AHEAD',
26+
\SplFileObject::SKIP_EMPTY => 'SKIP_EMPTY',
27+
\SplFileObject::READ_CSV => 'READ_CSV',
28+
);
29+
2330
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested)
2431
{
2532
$prefix = Caster::PREFIX_VIRTUAL;
@@ -122,6 +129,55 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
122129
return $a;
123130
}
124131

132+
public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested)
133+
{
134+
static $map = array(
135+
'csvControl' => 'getCsvControl',
136+
'flags' => 'getFlags',
137+
'maxLineLen' => 'getMaxLineLen',
138+
'fstat' => 'fstat',
139+
'eof' => 'eof',
140+
'key' => 'key',
141+
);
142+
143+
$prefix = Caster::PREFIX_VIRTUAL;
144+
145+
foreach ($map as $key => $accessor) {
146+
try {
147+
$a[$prefix.$key] = $c->$accessor();
148+
} catch (\Exception $e) {
149+
}
150+
}
151+
152+
if (isset($a[$prefix.'flags'])) {
153+
$flagsArray = array();
154+
foreach (self::$splFileObjectFlags as $value => $name) {
155+
if ($a[$prefix.'flags'] & $value) {
156+
$flagsArray[] = $name;
157+
}
158+
}
159+
$a[$prefix.'flags'] = new ConstStub(implode('|', $flagsArray), $a[$prefix.'flags']);
160+
}
161+
162+
163+
if (isset($a[$prefix.'fstat'])) {
164+
$fstat = $a[$prefix.'fstat'];
165+
$fstat = array(
166+
'dev' => $fstat['dev'],
167+
'ino' => $fstat['ino'],
168+
'nlink' => $fstat['nlink'],
169+
'rdev' => $fstat['rdev'],
170+
'blksize' => $fstat['blksize'],
171+
'blocks' => $fstat['blocks'],
172+
'' => ''.(count($fstat) - 6),
173+
);
174+
175+
$a[$prefix.'fstat'] = $fstat;
176+
}
177+
178+
return $a;
179+
}
180+
125181
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
126182
{
127183
$a += array(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ abstract class AbstractCloner implements ClonerInterface
7979
'ArrayObject' => 'Symfony\Component\VarDumper\Caster\SplCaster::castArrayObject',
8080
'SplDoublyLinkedList' => 'Symfony\Component\VarDumper\Caster\SplCaster::castDoublyLinkedList',
8181
'SplFileInfo' => 'Symfony\Component\VarDumper\Caster\SplCaster::castFileInfo',
82+
'SplFileObject' => 'Symfony\Component\VarDumper\Caster\SplCaster::castFileObject',
8283
'SplFixedArray' => 'Symfony\Component\VarDumper\Caster\SplCaster::castFixedArray',
8384
'SplHeap' => 'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
8485
'SplObjectStorage' => 'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy