Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfffa79a

Browse files
committed
[VarDumper] Added support for SplFileObject
1 parenteb50b13 commitfffa79a

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
*/
2121
class SplCaster
2222
{
23+
privatestatic$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
publicstaticfunctioncastArrayObject(\ArrayObject$c,array$a,Stub$stub,$isNested)
2431
{
2532
$prefix = Caster::PREFIX_VIRTUAL;
@@ -122,6 +129,54 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
122129
return$a;
123130
}
124131

132+
publicstaticfunctioncastFileObject(\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 ($mapas$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::$splFileObjectFlagsas$value =>$name) {
155+
if ($a[$prefix.'flags'] &$value) {
156+
$flagsArray[] =$name;
157+
}
158+
}
159+
$a[$prefix.'flags'] =newConstStub(implode('|',$flagsArray),$a[$prefix.'flags']);
160+
}
161+
162+
if (isset($a[$prefix.'fstat'])) {
163+
$fstat =$a[$prefix.'fstat'];
164+
$fstat =array(
165+
'dev' =>$fstat['dev'],
166+
'ino' =>$fstat['ino'],
167+
'nlink' =>$fstat['nlink'],
168+
'rdev' =>$fstat['rdev'],
169+
'blksize' =>$fstat['blksize'],
170+
'blocks' =>$fstat['blocks'],
171+
'' =>''.(count($fstat) -6),
172+
);
173+
174+
$a[$prefix.'fstat'] =$fstat;
175+
}
176+
177+
return$a;
178+
}
179+
125180
publicstaticfunctioncastFixedArray(\SplFixedArray$c,array$a,Stub$stub,$isNested)
126181
{
127182
$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',

‎src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function getCastFileInfoTests()
3434
cTime: %s-%s-%d %d:%d:%d
3535
inode: %d
3636
size: %d
37-
perms:0100644
38-
owner:1000
39-
group:1000
37+
perms:0%d
38+
owner:%d
39+
group:%d
4040
type: "file"
4141
writable: true
4242
readable: true
@@ -72,4 +72,53 @@ public function testCastFileInfo($file, $dump)
7272
{
7373
$this->assertDumpMatchesFormat($dump,new \SplFileInfo($file));
7474
}
75+
76+
publicfunctiontestCastFileObject()
77+
{
78+
$var =new \SplFileObject(__FILE__);
79+
$var->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
80+
$dump = <<<'EOTXT'
81+
SplFileObject {
82+
path: "%s/src/Symfony/Component/VarDumper/Tests/Caster"
83+
filename: "SplCasterTest.php"
84+
basename: "SplCasterTest.php"
85+
pathname: "%s/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php"
86+
extension: "php"
87+
realPath: "%s/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php"
88+
aTime: %s-%s-%d %d:%d:%d
89+
mTime: %s-%s-%d %d:%d:%d
90+
cTime: %s-%s-%d %d:%d:%d
91+
inode: %d
92+
size: %d
93+
perms: 0%d
94+
owner: %d
95+
group: %d
96+
type: "file"
97+
writable: true
98+
readable: true
99+
executable: false
100+
file: true
101+
dir: false
102+
link: false
103+
csvControl: array:2 [
104+
0 => ","
105+
1 => """
106+
]
107+
flags: DROP_NEW_LINE|SKIP_EMPTY
108+
maxLineLen: 0
109+
fstat: array:7 [
110+
"dev" => %d
111+
"ino" => %d
112+
"nlink" => %d
113+
"rdev" => 0
114+
"blksize" => %d
115+
"blocks" => %d
116+
"…" => "…20"
117+
]
118+
eof: false
119+
key: 0
120+
}
121+
EOTXT;
122+
$this->assertDumpMatchesFormat($dump,$var);
123+
}
75124
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp