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

Commitda3e50a

Browse files
[VarDumper] casters for SPL data structures
1 parentc91bc83 commitda3e50a

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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+
namespaceSymfony\Component\VarDumper\Caster;
13+
14+
/**
15+
* Casts SPL related classes to array representation.
16+
*
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class SplCaster
20+
{
21+
publicstaticfunctioncastArrayObject(\ArrayObject$c,array$a)
22+
{
23+
$class =get_class($c);
24+
$flags =$c->getFlags();
25+
26+
$b =array(
27+
"\0~\0flag::STD_PROP_LIST" => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
28+
"\0~\0flag::ARRAY_AS_PROPS" => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
29+
"\0~\0iteratorClass" =>$c->getIteratorClass(),
30+
"\0~\0storage" =>$c->getArrayCopy(),
31+
);
32+
33+
if ($class ==='ArrayObject') {
34+
$a =$b;
35+
}else {
36+
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
37+
$c->setFlags(\ArrayObject::STD_PROP_LIST);
38+
39+
if ($a = (array)$c) {
40+
$class =new \ReflectionClass($class);
41+
foreach ($aas$k =>$p) {
42+
if (!isset($k[0]) || ("\0" !==$k[0] && !$class->hasProperty($k))) {
43+
unset($a[$k]);
44+
$a["\0+\0".$k] =$p;
45+
}
46+
}
47+
}
48+
49+
$c->setFlags($flags);
50+
}
51+
52+
$a +=$b;
53+
}
54+
55+
return$a;
56+
}
57+
58+
publicstaticfunctioncastHeap(\Iterator$c,array$a)
59+
{
60+
$a +=array(
61+
"\0~\0heap" =>iterator_to_array(clone$c),
62+
);
63+
64+
return$a;
65+
}
66+
67+
publicstaticfunctioncastDoublyLinkedList(\SplDoublyLinkedList$c,array$a)
68+
{
69+
$mode =$c->getIteratorMode();
70+
$c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP |$mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
71+
72+
$a +=array(
73+
"\0~\0mode" => (($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ?'IT_MODE_LIFO' :'IT_MODE_FIFO').' |'.(($mode & \SplDoublyLinkedList::IT_MODE_KEEP) ?'IT_MODE_KEEP' :'IT_MODE_DELETE'),
74+
"\0~\0dllist" =>iterator_to_array($c),
75+
);
76+
$c->setIteratorMode($mode);
77+
78+
return$a;
79+
}
80+
81+
publicstaticfunctioncastFixedArray(\SplFixedArray$c,array$a)
82+
{
83+
$a +=array(
84+
"\0~\0storage" =>$c->toArray(),
85+
);
86+
87+
return$a;
88+
}
89+
90+
publicstaticfunctioncastObjectStorage(\SplObjectStorage$c,array$a)
91+
{
92+
$storage =array();
93+
unset($a["\0+\0\0gcdata"]);// Don't hit https://bugs.php.net/65967
94+
95+
foreach ($cas$obj) {
96+
$storage[spl_object_hash($obj)] =array(
97+
'object' =>$obj,
98+
'info' =>$c->getInfo(),
99+
);
100+
}
101+
102+
$a +=array(
103+
"\0~\0storage" =>$storage,
104+
);
105+
106+
return$a;
107+
}
108+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ abstract class AbstractCloner implements ClonerInterface
2929
'o:Symfony\Component\VarDumper\Exception\ThrowingCasterException'
3030
=>'Symfony\Component\VarDumper\Caster\ExceptionCaster::castThrowingCasterException',
3131

32+
'o:ArrayObject' =>'Symfony\Component\VarDumper\Caster\SplCaster::castArrayObject',
33+
'o:SplDoublyLinkedList' =>'Symfony\Component\VarDumper\Caster\SplCaster::castDoublyLinkedList',
34+
'o:SplFixedArray' =>'Symfony\Component\VarDumper\Caster\SplCaster::castFixedArray',
35+
'o:SplHeap' =>'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
36+
'o:SplObjectStorage' =>'Symfony\Component\VarDumper\Caster\SplCaster::castObjectStorage',
37+
'o:SplPriorityQueue' =>'Symfony\Component\VarDumper\Caster\SplCaster::castHeap',
38+
3239
'r:curl' =>'Symfony\Component\VarDumper\Caster\ResourceCaster::castCurl',
3340
'r:dba' =>'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',
3441
'r:dba persistent' =>'Symfony\Component\VarDumper\Caster\ResourceCaster::castDba',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp