Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/var-dumper/Caster/SplCaster.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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 namespace Symfony\Component\VarDumper\Caster; | |
13 | |
14 use Symfony\Component\VarDumper\Cloner\Stub; | |
15 | |
16 /** | |
17 * Casts SPL related classes to array representation. | |
18 * | |
19 * @author Nicolas Grekas <p@tchwork.com> | |
20 */ | |
21 class SplCaster | |
22 { | |
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 | |
30 public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested) | |
31 { | |
32 return self::castSplArray($c, $a, $stub, $isNested); | |
33 } | |
34 | |
35 public static function castArrayIterator(\ArrayIterator $c, array $a, Stub $stub, $isNested) | |
36 { | |
37 return self::castSplArray($c, $a, $stub, $isNested); | |
38 } | |
39 | |
40 public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested) | |
41 { | |
42 $a += array( | |
43 Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c), | |
44 ); | |
45 | |
46 return $a; | |
47 } | |
48 | |
49 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested) | |
50 { | |
51 $prefix = Caster::PREFIX_VIRTUAL; | |
52 $mode = $c->getIteratorMode(); | |
53 $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE); | |
54 | |
55 $a += array( | |
56 $prefix.'mode' => new ConstStub((($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO').' | '.(($mode & \SplDoublyLinkedList::IT_MODE_DELETE) ? 'IT_MODE_DELETE' : 'IT_MODE_KEEP'), $mode), | |
57 $prefix.'dllist' => iterator_to_array($c), | |
58 ); | |
59 $c->setIteratorMode($mode); | |
60 | |
61 return $a; | |
62 } | |
63 | |
64 public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNested) | |
65 { | |
66 static $map = array( | |
67 'path' => 'getPath', | |
68 'filename' => 'getFilename', | |
69 'basename' => 'getBasename', | |
70 'pathname' => 'getPathname', | |
71 'extension' => 'getExtension', | |
72 'realPath' => 'getRealPath', | |
73 'aTime' => 'getATime', | |
74 'mTime' => 'getMTime', | |
75 'cTime' => 'getCTime', | |
76 'inode' => 'getInode', | |
77 'size' => 'getSize', | |
78 'perms' => 'getPerms', | |
79 'owner' => 'getOwner', | |
80 'group' => 'getGroup', | |
81 'type' => 'getType', | |
82 'writable' => 'isWritable', | |
83 'readable' => 'isReadable', | |
84 'executable' => 'isExecutable', | |
85 'file' => 'isFile', | |
86 'dir' => 'isDir', | |
87 'link' => 'isLink', | |
88 'linkTarget' => 'getLinkTarget', | |
89 ); | |
90 | |
91 $prefix = Caster::PREFIX_VIRTUAL; | |
92 | |
93 foreach ($map as $key => $accessor) { | |
94 try { | |
95 $a[$prefix.$key] = $c->$accessor(); | |
96 } catch (\Exception $e) { | |
97 } | |
98 } | |
99 | |
100 if (isset($a[$prefix.'realPath'])) { | |
101 $a[$prefix.'realPath'] = new LinkStub($a[$prefix.'realPath']); | |
102 } | |
103 | |
104 if (isset($a[$prefix.'perms'])) { | |
105 $a[$prefix.'perms'] = new ConstStub(sprintf('0%o', $a[$prefix.'perms']), $a[$prefix.'perms']); | |
106 } | |
107 | |
108 static $mapDate = array('aTime', 'mTime', 'cTime'); | |
109 foreach ($mapDate as $key) { | |
110 if (isset($a[$prefix.$key])) { | |
111 $a[$prefix.$key] = new ConstStub(date('Y-m-d H:i:s', $a[$prefix.$key]), $a[$prefix.$key]); | |
112 } | |
113 } | |
114 | |
115 return $a; | |
116 } | |
117 | |
118 public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested) | |
119 { | |
120 static $map = array( | |
121 'csvControl' => 'getCsvControl', | |
122 'flags' => 'getFlags', | |
123 'maxLineLen' => 'getMaxLineLen', | |
124 'fstat' => 'fstat', | |
125 'eof' => 'eof', | |
126 'key' => 'key', | |
127 ); | |
128 | |
129 $prefix = Caster::PREFIX_VIRTUAL; | |
130 | |
131 foreach ($map as $key => $accessor) { | |
132 try { | |
133 $a[$prefix.$key] = $c->$accessor(); | |
134 } catch (\Exception $e) { | |
135 } | |
136 } | |
137 | |
138 if (isset($a[$prefix.'flags'])) { | |
139 $flagsArray = array(); | |
140 foreach (self::$splFileObjectFlags as $value => $name) { | |
141 if ($a[$prefix.'flags'] & $value) { | |
142 $flagsArray[] = $name; | |
143 } | |
144 } | |
145 $a[$prefix.'flags'] = new ConstStub(implode('|', $flagsArray), $a[$prefix.'flags']); | |
146 } | |
147 | |
148 if (isset($a[$prefix.'fstat'])) { | |
149 $a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], array('dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks')); | |
150 } | |
151 | |
152 return $a; | |
153 } | |
154 | |
155 public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) | |
156 { | |
157 $a += array( | |
158 Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(), | |
159 ); | |
160 | |
161 return $a; | |
162 } | |
163 | |
164 public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested) | |
165 { | |
166 $storage = array(); | |
167 unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967 | |
168 | |
169 $clone = clone $c; | |
170 foreach ($clone as $obj) { | |
171 $storage[] = array( | |
172 'object' => $obj, | |
173 'info' => $clone->getInfo(), | |
174 ); | |
175 } | |
176 | |
177 $a += array( | |
178 Caster::PREFIX_VIRTUAL.'storage' => $storage, | |
179 ); | |
180 | |
181 return $a; | |
182 } | |
183 | |
184 public static function castOuterIterator(\OuterIterator $c, array $a, Stub $stub, $isNested) | |
185 { | |
186 $a[Caster::PREFIX_VIRTUAL.'innerIterator'] = $c->getInnerIterator(); | |
187 | |
188 return $a; | |
189 } | |
190 | |
191 private static function castSplArray($c, array $a, Stub $stub, $isNested) | |
192 { | |
193 $prefix = Caster::PREFIX_VIRTUAL; | |
194 $class = $stub->class; | |
195 $flags = $c->getFlags(); | |
196 | |
197 if (!($flags & \ArrayObject::STD_PROP_LIST)) { | |
198 $c->setFlags(\ArrayObject::STD_PROP_LIST); | |
199 $a = Caster::castObject($c, $class); | |
200 $c->setFlags($flags); | |
201 } | |
202 $a += array( | |
203 $prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST), | |
204 $prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS), | |
205 ); | |
206 if ($c instanceof \ArrayObject) { | |
207 $a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass()); | |
208 } | |
209 $a[$prefix.'storage'] = $c->getArrayCopy(); | |
210 | |
211 return $a; | |
212 } | |
213 } |