Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Caster/SplCaster.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
18 * | 18 * |
19 * @author Nicolas Grekas <p@tchwork.com> | 19 * @author Nicolas Grekas <p@tchwork.com> |
20 */ | 20 */ |
21 class SplCaster | 21 class SplCaster |
22 { | 22 { |
23 private static $splFileObjectFlags = array( | 23 private static $splFileObjectFlags = [ |
24 \SplFileObject::DROP_NEW_LINE => 'DROP_NEW_LINE', | 24 \SplFileObject::DROP_NEW_LINE => 'DROP_NEW_LINE', |
25 \SplFileObject::READ_AHEAD => 'READ_AHEAD', | 25 \SplFileObject::READ_AHEAD => 'READ_AHEAD', |
26 \SplFileObject::SKIP_EMPTY => 'SKIP_EMPTY', | 26 \SplFileObject::SKIP_EMPTY => 'SKIP_EMPTY', |
27 \SplFileObject::READ_CSV => 'READ_CSV', | 27 \SplFileObject::READ_CSV => 'READ_CSV', |
28 ); | 28 ]; |
29 | 29 |
30 public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested) | 30 public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested) |
31 { | 31 { |
32 return self::castSplArray($c, $a, $stub, $isNested); | 32 return self::castSplArray($c, $a, $stub, $isNested); |
33 } | 33 } |
37 return self::castSplArray($c, $a, $stub, $isNested); | 37 return self::castSplArray($c, $a, $stub, $isNested); |
38 } | 38 } |
39 | 39 |
40 public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested) | 40 public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested) |
41 { | 41 { |
42 $a += array( | 42 $a += [ |
43 Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c), | 43 Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c), |
44 ); | 44 ]; |
45 | 45 |
46 return $a; | 46 return $a; |
47 } | 47 } |
48 | 48 |
49 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested) | 49 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested) |
50 { | 50 { |
51 $prefix = Caster::PREFIX_VIRTUAL; | 51 $prefix = Caster::PREFIX_VIRTUAL; |
52 $mode = $c->getIteratorMode(); | 52 $mode = $c->getIteratorMode(); |
53 $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE); | 53 $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE); |
54 | 54 |
55 $a += array( | 55 $a += [ |
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), | 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), | 57 $prefix.'dllist' => iterator_to_array($c), |
58 ); | 58 ]; |
59 $c->setIteratorMode($mode); | 59 $c->setIteratorMode($mode); |
60 | 60 |
61 return $a; | 61 return $a; |
62 } | 62 } |
63 | 63 |
64 public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNested) | 64 public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNested) |
65 { | 65 { |
66 static $map = array( | 66 static $map = [ |
67 'path' => 'getPath', | 67 'path' => 'getPath', |
68 'filename' => 'getFilename', | 68 'filename' => 'getFilename', |
69 'basename' => 'getBasename', | 69 'basename' => 'getBasename', |
70 'pathname' => 'getPathname', | 70 'pathname' => 'getPathname', |
71 'extension' => 'getExtension', | 71 'extension' => 'getExtension', |
84 'executable' => 'isExecutable', | 84 'executable' => 'isExecutable', |
85 'file' => 'isFile', | 85 'file' => 'isFile', |
86 'dir' => 'isDir', | 86 'dir' => 'isDir', |
87 'link' => 'isLink', | 87 'link' => 'isLink', |
88 'linkTarget' => 'getLinkTarget', | 88 'linkTarget' => 'getLinkTarget', |
89 ); | 89 ]; |
90 | 90 |
91 $prefix = Caster::PREFIX_VIRTUAL; | 91 $prefix = Caster::PREFIX_VIRTUAL; |
92 | 92 |
93 foreach ($map as $key => $accessor) { | 93 foreach ($map as $key => $accessor) { |
94 try { | 94 try { |
103 | 103 |
104 if (isset($a[$prefix.'perms'])) { | 104 if (isset($a[$prefix.'perms'])) { |
105 $a[$prefix.'perms'] = new ConstStub(sprintf('0%o', $a[$prefix.'perms']), $a[$prefix.'perms']); | 105 $a[$prefix.'perms'] = new ConstStub(sprintf('0%o', $a[$prefix.'perms']), $a[$prefix.'perms']); |
106 } | 106 } |
107 | 107 |
108 static $mapDate = array('aTime', 'mTime', 'cTime'); | 108 static $mapDate = ['aTime', 'mTime', 'cTime']; |
109 foreach ($mapDate as $key) { | 109 foreach ($mapDate as $key) { |
110 if (isset($a[$prefix.$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]); | 111 $a[$prefix.$key] = new ConstStub(date('Y-m-d H:i:s', $a[$prefix.$key]), $a[$prefix.$key]); |
112 } | 112 } |
113 } | 113 } |
115 return $a; | 115 return $a; |
116 } | 116 } |
117 | 117 |
118 public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested) | 118 public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested) |
119 { | 119 { |
120 static $map = array( | 120 static $map = [ |
121 'csvControl' => 'getCsvControl', | 121 'csvControl' => 'getCsvControl', |
122 'flags' => 'getFlags', | 122 'flags' => 'getFlags', |
123 'maxLineLen' => 'getMaxLineLen', | 123 'maxLineLen' => 'getMaxLineLen', |
124 'fstat' => 'fstat', | 124 'fstat' => 'fstat', |
125 'eof' => 'eof', | 125 'eof' => 'eof', |
126 'key' => 'key', | 126 'key' => 'key', |
127 ); | 127 ]; |
128 | 128 |
129 $prefix = Caster::PREFIX_VIRTUAL; | 129 $prefix = Caster::PREFIX_VIRTUAL; |
130 | 130 |
131 foreach ($map as $key => $accessor) { | 131 foreach ($map as $key => $accessor) { |
132 try { | 132 try { |
134 } catch (\Exception $e) { | 134 } catch (\Exception $e) { |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 if (isset($a[$prefix.'flags'])) { | 138 if (isset($a[$prefix.'flags'])) { |
139 $flagsArray = array(); | 139 $flagsArray = []; |
140 foreach (self::$splFileObjectFlags as $value => $name) { | 140 foreach (self::$splFileObjectFlags as $value => $name) { |
141 if ($a[$prefix.'flags'] & $value) { | 141 if ($a[$prefix.'flags'] & $value) { |
142 $flagsArray[] = $name; | 142 $flagsArray[] = $name; |
143 } | 143 } |
144 } | 144 } |
145 $a[$prefix.'flags'] = new ConstStub(implode('|', $flagsArray), $a[$prefix.'flags']); | 145 $a[$prefix.'flags'] = new ConstStub(implode('|', $flagsArray), $a[$prefix.'flags']); |
146 } | 146 } |
147 | 147 |
148 if (isset($a[$prefix.'fstat'])) { | 148 if (isset($a[$prefix.'fstat'])) { |
149 $a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], array('dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks')); | 149 $a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], ['dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks']); |
150 } | 150 } |
151 | 151 |
152 return $a; | 152 return $a; |
153 } | 153 } |
154 | 154 |
155 public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) | 155 public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) |
156 { | 156 { |
157 $a += array( | 157 $a += [ |
158 Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(), | 158 Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(), |
159 ); | 159 ]; |
160 | 160 |
161 return $a; | 161 return $a; |
162 } | 162 } |
163 | 163 |
164 public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested) | 164 public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested) |
165 { | 165 { |
166 $storage = array(); | 166 $storage = []; |
167 unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967 | 167 unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967 |
168 | 168 |
169 $clone = clone $c; | 169 $clone = clone $c; |
170 foreach ($clone as $obj) { | 170 foreach ($clone as $obj) { |
171 $storage[] = array( | 171 $storage[] = [ |
172 'object' => $obj, | 172 'object' => $obj, |
173 'info' => $clone->getInfo(), | 173 'info' => $clone->getInfo(), |
174 ); | 174 ]; |
175 } | 175 } |
176 | 176 |
177 $a += array( | 177 $a += [ |
178 Caster::PREFIX_VIRTUAL.'storage' => $storage, | 178 Caster::PREFIX_VIRTUAL.'storage' => $storage, |
179 ); | 179 ]; |
180 | 180 |
181 return $a; | 181 return $a; |
182 } | 182 } |
183 | 183 |
184 public static function castOuterIterator(\OuterIterator $c, array $a, Stub $stub, $isNested) | 184 public static function castOuterIterator(\OuterIterator $c, array $a, Stub $stub, $isNested) |
197 if (!($flags & \ArrayObject::STD_PROP_LIST)) { | 197 if (!($flags & \ArrayObject::STD_PROP_LIST)) { |
198 $c->setFlags(\ArrayObject::STD_PROP_LIST); | 198 $c->setFlags(\ArrayObject::STD_PROP_LIST); |
199 $a = Caster::castObject($c, $class); | 199 $a = Caster::castObject($c, $class); |
200 $c->setFlags($flags); | 200 $c->setFlags($flags); |
201 } | 201 } |
202 $a += array( | 202 $a += [ |
203 $prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST), | 203 $prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST), |
204 $prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS), | 204 $prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS), |
205 ); | 205 ]; |
206 if ($c instanceof \ArrayObject) { | 206 if ($c instanceof \ArrayObject) { |
207 $a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass()); | 207 $a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass()); |
208 } | 208 } |
209 $a[$prefix.'storage'] = $c->getArrayCopy(); | 209 $a[$prefix.'storage'] = $c->getArrayCopy(); |
210 | 210 |