|
| 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 | +} |