Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/var-dumper/Cloner/VarCloner.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
25 * {@inheritdoc} | 25 * {@inheritdoc} |
26 */ | 26 */ |
27 protected function doClone($var) | 27 protected function doClone($var) |
28 { | 28 { |
29 $len = 1; // Length of $queue | 29 $len = 1; // Length of $queue |
30 $pos = 0; // Number of cloned items past the first level | 30 $pos = 0; // Number of cloned items past the minimum depth |
31 $refsCounter = 0; // Hard references counter | 31 $refsCounter = 0; // Hard references counter |
32 $queue = array(array($var)); // This breadth-first queue is the return value | 32 $queue = array(array($var)); // This breadth-first queue is the return value |
33 $indexedArrays = array(); // Map of queue indexes that hold numerically indexed arrays | 33 $indexedArrays = array(); // Map of queue indexes that hold numerically indexed arrays |
34 $hardRefs = array(); // Map of original zval hashes to stub objects | 34 $hardRefs = array(); // Map of original zval hashes to stub objects |
35 $objRefs = array(); // Map of original object handles to their stub object couterpart | 35 $objRefs = array(); // Map of original object handles to their stub object couterpart |
36 $resRefs = array(); // Map of original resource handles to their stub object couterpart | 36 $resRefs = array(); // Map of original resource handles to their stub object couterpart |
37 $values = array(); // Map of stub objects' hashes to original values | 37 $values = array(); // Map of stub objects' hashes to original values |
38 $maxItems = $this->maxItems; | 38 $maxItems = $this->maxItems; |
39 $maxString = $this->maxString; | 39 $maxString = $this->maxString; |
40 $minDepth = $this->minDepth; | |
41 $currentDepth = 0; // Current tree depth | |
42 $currentDepthFinalIndex = 0; // Final $queue index for current tree depth | |
43 $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached | |
40 $cookie = (object) array(); // Unique object used to detect hard references | 44 $cookie = (object) array(); // Unique object used to detect hard references |
41 $a = null; // Array cast for nested structures | 45 $a = null; // Array cast for nested structures |
42 $stub = null; // Stub capturing the main properties of an original item value | 46 $stub = null; // Stub capturing the main properties of an original item value |
43 // or null if the original value is used directly | 47 // or null if the original value is used directly |
44 | 48 |
52 $arrayStub = new Stub(); | 56 $arrayStub = new Stub(); |
53 $arrayStub->type = Stub::TYPE_ARRAY; | 57 $arrayStub->type = Stub::TYPE_ARRAY; |
54 $fromObjCast = false; | 58 $fromObjCast = false; |
55 | 59 |
56 for ($i = 0; $i < $len; ++$i) { | 60 for ($i = 0; $i < $len; ++$i) { |
61 // Detect when we move on to the next tree depth | |
62 if ($i > $currentDepthFinalIndex) { | |
63 ++$currentDepth; | |
64 $currentDepthFinalIndex = $len - 1; | |
65 if ($currentDepth >= $minDepth) { | |
66 $minimumDepthReached = true; | |
67 } | |
68 } | |
69 | |
57 $refs = $vals = $queue[$i]; | 70 $refs = $vals = $queue[$i]; |
58 if (\PHP_VERSION_ID < 70200 && empty($indexedArrays[$i])) { | 71 if (\PHP_VERSION_ID < 70200 && empty($indexedArrays[$i])) { |
59 // see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts | 72 // see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts |
60 foreach ($vals as $k => $v) { | 73 foreach ($vals as $k => $v) { |
61 if (\is_int($k)) { | 74 if (\is_int($k)) { |
92 $vals[$k]->handle = ++$refsCounter; | 105 $vals[$k]->handle = ++$refsCounter; |
93 } | 106 } |
94 // Create $stub when the original value $v can not be used directly | 107 // Create $stub when the original value $v can not be used directly |
95 // If $v is a nested structure, put that structure in array $a | 108 // If $v is a nested structure, put that structure in array $a |
96 switch (true) { | 109 switch (true) { |
97 case empty($v): | 110 case null === $v: |
98 case true === $v: | 111 case \is_bool($v): |
99 case \is_int($v): | 112 case \is_int($v): |
100 case \is_float($v): | 113 case \is_float($v): |
101 continue 2; | 114 continue 2; |
102 | 115 |
103 case \is_string($v): | 116 case \is_string($v): |
117 if ('' === $v) { | |
118 continue 2; | |
119 } | |
104 if (!\preg_match('//u', $v)) { | 120 if (!\preg_match('//u', $v)) { |
105 $stub = new Stub(); | 121 $stub = new Stub(); |
106 $stub->type = Stub::TYPE_STRING; | 122 $stub->type = Stub::TYPE_STRING; |
107 $stub->class = Stub::STRING_BINARY; | 123 $stub->class = Stub::STRING_BINARY; |
108 if (0 <= $maxString && 0 < $cut = \strlen($v) - $maxString) { | 124 if (0 <= $maxString && 0 < $cut = \strlen($v) - $maxString) { |
122 } | 138 } |
123 $a = null; | 139 $a = null; |
124 break; | 140 break; |
125 | 141 |
126 case \is_array($v): | 142 case \is_array($v): |
143 if (!$v) { | |
144 continue 2; | |
145 } | |
127 $stub = $arrayStub; | 146 $stub = $arrayStub; |
128 $stub->class = Stub::ARRAY_INDEXED; | 147 $stub->class = Stub::ARRAY_INDEXED; |
129 | 148 |
130 $j = -1; | 149 $j = -1; |
131 foreach ($v as $gk => $gv) { | 150 foreach ($v as $gk => $gv) { |
172 } | 191 } |
173 $h = $hashMask ^ \hexdec(\substr(\spl_object_hash($stub->value), $hashOffset, \PHP_INT_SIZE)); | 192 $h = $hashMask ^ \hexdec(\substr(\spl_object_hash($stub->value), $hashOffset, \PHP_INT_SIZE)); |
174 $stub->handle = $h; | 193 $stub->handle = $h; |
175 } | 194 } |
176 $stub->value = null; | 195 $stub->value = null; |
177 if (0 <= $maxItems && $maxItems <= $pos) { | 196 if (0 <= $maxItems && $maxItems <= $pos && $minimumDepthReached) { |
178 $stub->cut = \count($a); | 197 $stub->cut = \count($a); |
179 $a = null; | 198 $a = null; |
180 } | 199 } |
181 } | 200 } |
182 if (empty($objRefs[$h])) { | 201 if (empty($objRefs[$h])) { |
197 } | 216 } |
198 $stub->value = $v; | 217 $stub->value = $v; |
199 $stub->handle = $h; | 218 $stub->handle = $h; |
200 $a = $this->castResource($stub, 0 < $i); | 219 $a = $this->castResource($stub, 0 < $i); |
201 $stub->value = null; | 220 $stub->value = null; |
202 if (0 <= $maxItems && $maxItems <= $pos) { | 221 if (0 <= $maxItems && $maxItems <= $pos && $minimumDepthReached) { |
203 $stub->cut = \count($a); | 222 $stub->cut = \count($a); |
204 $a = null; | 223 $a = null; |
205 } | 224 } |
206 } | 225 } |
207 if (empty($resRefs[$h])) { | 226 if (empty($resRefs[$h])) { |
213 } | 232 } |
214 break; | 233 break; |
215 } | 234 } |
216 | 235 |
217 if ($a) { | 236 if ($a) { |
218 if (!$i || 0 > $maxItems) { | 237 if (!$minimumDepthReached || 0 > $maxItems) { |
219 $queue[$len] = $a; | 238 $queue[$len] = $a; |
220 $stub->position = $len++; | 239 $stub->position = $len++; |
221 } elseif ($pos < $maxItems) { | 240 } elseif ($pos < $maxItems) { |
222 if ($maxItems < $pos += \count($a)) { | 241 if ($maxItems < $pos += \count($a)) { |
223 $a = \array_slice($a, 0, $maxItems - $pos); | 242 $a = \array_slice($a, 0, $maxItems - $pos); |