Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/var-dumper/Cloner/Data.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
42 | 42 |
43 if ($item instanceof Stub && Stub::TYPE_REF === $item->type && !$item->position) { | 43 if ($item instanceof Stub && Stub::TYPE_REF === $item->type && !$item->position) { |
44 $item = $item->value; | 44 $item = $item->value; |
45 } | 45 } |
46 if (!$item instanceof Stub) { | 46 if (!$item instanceof Stub) { |
47 return gettype($item); | 47 return \gettype($item); |
48 } | 48 } |
49 if (Stub::TYPE_STRING === $item->type) { | 49 if (Stub::TYPE_STRING === $item->type) { |
50 return 'string'; | 50 return 'string'; |
51 } | 51 } |
52 if (Stub::TYPE_ARRAY === $item->type) { | 52 if (Stub::TYPE_ARRAY === $item->type) { |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * @param bool $recursive Whether values should be resolved recursively or not | 64 * @param bool $recursive Whether values should be resolved recursively or not |
65 * | 65 * |
66 * @return string|int|float|bool|array|null|Data[] A native representation of the original value | 66 * @return string|int|float|bool|array|Data[]|null A native representation of the original value |
67 */ | 67 */ |
68 public function getValue($recursive = false) | 68 public function getValue($recursive = false) |
69 { | 69 { |
70 $item = $this->data[$this->position][$this->key]; | 70 $item = $this->data[$this->position][$this->key]; |
71 | 71 |
77 } | 77 } |
78 if (Stub::TYPE_STRING === $item->type) { | 78 if (Stub::TYPE_STRING === $item->type) { |
79 return $item->value; | 79 return $item->value; |
80 } | 80 } |
81 | 81 |
82 $children = $item->position ? $this->data[$item->position] : array(); | 82 $children = $item->position ? $this->data[$item->position] : []; |
83 | 83 |
84 foreach ($children as $k => $v) { | 84 foreach ($children as $k => $v) { |
85 if ($recursive && !($v = $this->getStub($v)) instanceof Stub) { | 85 if ($recursive && !($v = $this->getStub($v)) instanceof Stub) { |
86 continue; | 86 continue; |
87 } | 87 } |
104 return $children; | 104 return $children; |
105 } | 105 } |
106 | 106 |
107 public function count() | 107 public function count() |
108 { | 108 { |
109 return count($this->getValue()); | 109 return \count($this->getValue()); |
110 } | 110 } |
111 | 111 |
112 public function getIterator() | 112 public function getIterator() |
113 { | 113 { |
114 if (!is_array($value = $this->getValue())) { | 114 if (!\is_array($value = $this->getValue())) { |
115 throw new \LogicException(sprintf('%s object holds non-iterable type "%s".', self::class, gettype($value))); | 115 throw new \LogicException(sprintf('%s object holds non-iterable type "%s".', self::class, \gettype($value))); |
116 } | 116 } |
117 | 117 |
118 foreach ($value as $k => $v) { | 118 foreach ($value as $k => $v) { |
119 yield $k => $v; | 119 yield $k => $v; |
120 } | 120 } |
123 public function __get($key) | 123 public function __get($key) |
124 { | 124 { |
125 if (null !== $data = $this->seek($key)) { | 125 if (null !== $data = $this->seek($key)) { |
126 $item = $this->getStub($data->data[$data->position][$data->key]); | 126 $item = $this->getStub($data->data[$data->position][$data->key]); |
127 | 127 |
128 return $item instanceof Stub || array() === $item ? $data : $item; | 128 return $item instanceof Stub || [] === $item ? $data : $item; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 public function __isset($key) | 132 public function __isset($key) |
133 { | 133 { |
156 | 156 |
157 public function __toString() | 157 public function __toString() |
158 { | 158 { |
159 $value = $this->getValue(); | 159 $value = $this->getValue(); |
160 | 160 |
161 if (!is_array($value)) { | 161 if (!\is_array($value)) { |
162 return (string) $value; | 162 return (string) $value; |
163 } | 163 } |
164 | 164 |
165 return sprintf('%s (count=%d)', $this->getType(), count($value)); | 165 return sprintf('%s (count=%d)', $this->getType(), \count($value)); |
166 } | 166 } |
167 | 167 |
168 /** | 168 /** |
169 * @return array The raw data structure | 169 * @return array The raw data structure |
170 * | 170 * |
171 * @deprecated since version 3.3. Use array or object access instead. | 171 * @deprecated since version 3.3. Use array or object access instead. |
172 */ | 172 */ |
173 public function getRawData() | 173 public function getRawData() |
174 { | 174 { |
175 @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the array or object access instead.', __METHOD__)); | 175 @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the array or object access instead.', __METHOD__)); |
176 | 176 |
177 return $this->data; | 177 return $this->data; |
178 } | 178 } |
179 | 179 |
180 /** | 180 /** |
237 $item = $item->value; | 237 $item = $item->value; |
238 } | 238 } |
239 if (!($item = $this->getStub($item)) instanceof Stub || !$item->position) { | 239 if (!($item = $this->getStub($item)) instanceof Stub || !$item->position) { |
240 return; | 240 return; |
241 } | 241 } |
242 $keys = array($key); | 242 $keys = [$key]; |
243 | 243 |
244 switch ($item->type) { | 244 switch ($item->type) { |
245 case Stub::TYPE_OBJECT: | 245 case Stub::TYPE_OBJECT: |
246 $keys[] = Caster::PREFIX_DYNAMIC.$key; | 246 $keys[] = Caster::PREFIX_DYNAMIC.$key; |
247 $keys[] = Caster::PREFIX_PROTECTED.$key; | 247 $keys[] = Caster::PREFIX_PROTECTED.$key; |
273 /** | 273 /** |
274 * Dumps data with a DumperInterface dumper. | 274 * Dumps data with a DumperInterface dumper. |
275 */ | 275 */ |
276 public function dump(DumperInterface $dumper) | 276 public function dump(DumperInterface $dumper) |
277 { | 277 { |
278 $refs = array(0); | 278 $refs = [0]; |
279 $this->dumpItem($dumper, new Cursor(), $refs, $this->data[$this->position][$this->key]); | 279 $this->dumpItem($dumper, new Cursor(), $refs, $this->data[$this->position][$this->key]); |
280 } | 280 } |
281 | 281 |
282 /** | 282 /** |
283 * Depth-first dumping of items. | 283 * Depth-first dumping of items. |
293 $cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0; | 293 $cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0; |
294 $cursor->hardRefTo = $cursor->hardRefHandle = $cursor->hardRefCount = 0; | 294 $cursor->hardRefTo = $cursor->hardRefHandle = $cursor->hardRefCount = 0; |
295 $firstSeen = true; | 295 $firstSeen = true; |
296 | 296 |
297 if (!$item instanceof Stub) { | 297 if (!$item instanceof Stub) { |
298 $cursor->attr = array(); | 298 $cursor->attr = []; |
299 $type = \gettype($item); | 299 $type = \gettype($item); |
300 if ($item && 'array' === $type) { | 300 if ($item && 'array' === $type) { |
301 $item = $this->getStub($item); | 301 $item = $this->getStub($item); |
302 } | 302 } |
303 } elseif (Stub::TYPE_REF === $item->type) { | 303 } elseif (Stub::TYPE_REF === $item->type) { |
310 $cursor->hardRefTo = $refs[$r]; | 310 $cursor->hardRefTo = $refs[$r]; |
311 $cursor->hardRefHandle = $this->useRefHandles & $item->handle; | 311 $cursor->hardRefHandle = $this->useRefHandles & $item->handle; |
312 $cursor->hardRefCount = $item->refCount; | 312 $cursor->hardRefCount = $item->refCount; |
313 } | 313 } |
314 $cursor->attr = $item->attr; | 314 $cursor->attr = $item->attr; |
315 $type = $item->class ?: gettype($item->value); | 315 $type = $item->class ?: \gettype($item->value); |
316 $item = $this->getStub($item->value); | 316 $item = $this->getStub($item->value); |
317 } | 317 } |
318 if ($item instanceof Stub) { | 318 if ($item instanceof Stub) { |
319 if ($item->refCount) { | 319 if ($item->refCount) { |
320 if (!isset($refs[$r = $item->handle])) { | 320 if (!isset($refs[$r = $item->handle])) { |
332 if ($item->position && $firstSeen) { | 332 if ($item->position && $firstSeen) { |
333 $children = $this->data[$item->position]; | 333 $children = $this->data[$item->position]; |
334 | 334 |
335 if ($cursor->stop) { | 335 if ($cursor->stop) { |
336 if ($cut >= 0) { | 336 if ($cut >= 0) { |
337 $cut += count($children); | 337 $cut += \count($children); |
338 } | 338 } |
339 $children = array(); | 339 $children = []; |
340 } | 340 } |
341 } else { | 341 } else { |
342 $children = array(); | 342 $children = []; |
343 } | 343 } |
344 switch ($item->type) { | 344 switch ($item->type) { |
345 case Stub::TYPE_STRING: | 345 case Stub::TYPE_STRING: |
346 $dumper->dumpString($cursor, $item->value, Stub::STRING_BINARY === $item->class, $cut); | 346 $dumper->dumpString($cursor, $item->value, Stub::STRING_BINARY === $item->class, $cut); |
347 break; | 347 break; |
361 $cut = -1; | 361 $cut = -1; |
362 } else { | 362 } else { |
363 $cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class); | 363 $cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class); |
364 } | 364 } |
365 } elseif ($children && 0 <= $cut) { | 365 } elseif ($children && 0 <= $cut) { |
366 $cut += count($children); | 366 $cut += \count($children); |
367 } | 367 } |
368 $cursor->skipChildren = false; | 368 $cursor->skipChildren = false; |
369 $dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut); | 369 $dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut); |
370 break; | 370 break; |
371 | 371 |
399 { | 399 { |
400 $cursor = clone $parentCursor; | 400 $cursor = clone $parentCursor; |
401 ++$cursor->depth; | 401 ++$cursor->depth; |
402 $cursor->hashType = $hashType; | 402 $cursor->hashType = $hashType; |
403 $cursor->hashIndex = 0; | 403 $cursor->hashIndex = 0; |
404 $cursor->hashLength = count($children); | 404 $cursor->hashLength = \count($children); |
405 $cursor->hashCut = $hashCut; | 405 $cursor->hashCut = $hashCut; |
406 foreach ($children as $key => $child) { | 406 foreach ($children as $key => $child) { |
407 $cursor->hashKeyIsBinary = isset($key[0]) && !preg_match('//u', $key); | 407 $cursor->hashKeyIsBinary = isset($key[0]) && !preg_match('//u', $key); |
408 $cursor->hashKey = $dumpKeys ? $key : null; | 408 $cursor->hashKey = $dumpKeys ? $key : null; |
409 $this->dumpItem($dumper, $cursor, $refs, $child); | 409 $this->dumpItem($dumper, $cursor, $refs, $child); |