diff 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
line wrap: on
line diff
--- a/vendor/symfony/var-dumper/Cloner/VarCloner.php	Fri Feb 23 15:51:18 2018 +0000
+++ b/vendor/symfony/var-dumper/Cloner/VarCloner.php	Fri Feb 23 15:52:07 2018 +0000
@@ -27,7 +27,7 @@
     protected function doClone($var)
     {
         $len = 1;                       // Length of $queue
-        $pos = 0;                       // Number of cloned items past the first level
+        $pos = 0;                       // Number of cloned items past the minimum depth
         $refsCounter = 0;               // Hard references counter
         $queue = array(array($var));    // This breadth-first queue is the return value
         $indexedArrays = array();       // Map of queue indexes that hold numerically indexed arrays
@@ -37,6 +37,10 @@
         $values = array();              // Map of stub objects' hashes to original values
         $maxItems = $this->maxItems;
         $maxString = $this->maxString;
+        $minDepth = $this->minDepth;
+        $currentDepth = 0;              // Current tree depth
+        $currentDepthFinalIndex = 0;    // Final $queue index for current tree depth
+        $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached
         $cookie = (object) array();     // Unique object used to detect hard references
         $a = null;                      // Array cast for nested structures
         $stub = null;                   // Stub capturing the main properties of an original item value
@@ -54,6 +58,15 @@
         $fromObjCast = false;
 
         for ($i = 0; $i < $len; ++$i) {
+            // Detect when we move on to the next tree depth
+            if ($i > $currentDepthFinalIndex) {
+                ++$currentDepth;
+                $currentDepthFinalIndex = $len - 1;
+                if ($currentDepth >= $minDepth) {
+                    $minimumDepthReached = true;
+                }
+            }
+
             $refs = $vals = $queue[$i];
             if (\PHP_VERSION_ID < 70200 && empty($indexedArrays[$i])) {
                 // see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
@@ -94,13 +107,16 @@
                 // Create $stub when the original value $v can not be used directly
                 // If $v is a nested structure, put that structure in array $a
                 switch (true) {
-                    case empty($v):
-                    case true === $v:
+                    case null === $v:
+                    case \is_bool($v):
                     case \is_int($v):
                     case \is_float($v):
                         continue 2;
 
                     case \is_string($v):
+                        if ('' === $v) {
+                            continue 2;
+                        }
                         if (!\preg_match('//u', $v)) {
                             $stub = new Stub();
                             $stub->type = Stub::TYPE_STRING;
@@ -124,6 +140,9 @@
                         break;
 
                     case \is_array($v):
+                        if (!$v) {
+                            continue 2;
+                        }
                         $stub = $arrayStub;
                         $stub->class = Stub::ARRAY_INDEXED;
 
@@ -174,7 +193,7 @@
                                 $stub->handle = $h;
                             }
                             $stub->value = null;
-                            if (0 <= $maxItems && $maxItems <= $pos) {
+                            if (0 <= $maxItems && $maxItems <= $pos && $minimumDepthReached) {
                                 $stub->cut = \count($a);
                                 $a = null;
                             }
@@ -199,7 +218,7 @@
                             $stub->handle = $h;
                             $a = $this->castResource($stub, 0 < $i);
                             $stub->value = null;
-                            if (0 <= $maxItems && $maxItems <= $pos) {
+                            if (0 <= $maxItems && $maxItems <= $pos && $minimumDepthReached) {
                                 $stub->cut = \count($a);
                                 $a = null;
                             }
@@ -215,7 +234,7 @@
                 }
 
                 if ($a) {
-                    if (!$i || 0 > $maxItems) {
+                    if (!$minimumDepthReached || 0 > $maxItems) {
                         $queue[$len] = $a;
                         $stub->position = $len++;
                     } elseif ($pos < $maxItems) {