[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/DataFormatter/VarDumper/ -> SeekingData.php (source)

   1  <?php
   2  
   3  namespace DebugBar\DataFormatter\VarDumper;
   4  
   5  use Symfony\Component\VarDumper\Cloner\Cursor;
   6  use Symfony\Component\VarDumper\Cloner\Data;
   7  use Symfony\Component\VarDumper\Cloner\DumperInterface;
   8  use Symfony\Component\VarDumper\Cloner\Stub;
   9  
  10  /**
  11   * This class backports the seek() function from Symfony 3.2 to older versions - up to v2.6.  The
  12   * class should not be used with newer Symfony versions that provide the seek function, as it relies
  13   * on a lot of undocumented functionality.
  14   */
  15  class SeekingData extends Data
  16  {
  17      // Because the class copies/pastes the seek() implementation from Symfony 3.2, we reproduce its
  18      // copyright here; this class is subject to the following additional copyright:
  19  
  20      /*
  21       * Copyright (c) 2014-2017 Fabien Potencier
  22       *
  23       * Permission is hereby granted, free of charge, to any person obtaining a copy
  24       * of this software and associated documentation files (the "Software"), to deal
  25       * in the Software without restriction, including without limitation the rights
  26       * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  27       * copies of the Software, and to permit persons to whom the Software is furnished
  28       * to do so, subject to the following conditions:
  29       *
  30       * The above copyright notice and this permission notice shall be included in all
  31       * copies or substantial portions of the Software.
  32       *
  33       * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34       * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35       * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36       * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37       * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38       * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  39       * THE SOFTWARE.
  40       */
  41      private $position = 0;
  42      private $key = 0;
  43  
  44      /**
  45       * Seeks to a specific key in nested data structures.
  46       *
  47       * @param string|int $key The key to seek to
  48       *
  49       * @return self|null A clone of $this of null if the key is not set
  50       */
  51      public function seek($key)
  52      {
  53          $thisData = $this->getRawData();
  54          $item = $thisData[$this->position][$this->key];
  55  
  56          if (!$item instanceof Stub || !$item->position) {
  57              return;
  58          }
  59          $keys = array($key);
  60  
  61          switch ($item->type) {
  62              case Stub::TYPE_OBJECT:
  63                  $keys[] = "\0+\0".$key;
  64                  $keys[] = "\0*\0".$key;
  65                  $keys[] = "\0~\0".$key;
  66                  $keys[] = "\0$item->class\0$key";
  67              case Stub::TYPE_ARRAY:
  68              case Stub::TYPE_RESOURCE:
  69                  break;
  70              default:
  71                  return;
  72          }
  73  
  74          $data = null;
  75          $children = $thisData[$item->position];
  76  
  77          foreach ($keys as $key) {
  78              if (isset($children[$key]) || array_key_exists($key, $children)) {
  79                  $data = clone $this;
  80                  $data->key = $key;
  81                  $data->position = $item->position;
  82                  break;
  83              }
  84          }
  85  
  86          return $data;
  87      }
  88  
  89      /**
  90       * {@inheritdoc}
  91       */
  92      public function dump(DumperInterface $dumper)
  93      {
  94          // Override the base class dump to use the position and key
  95          $refs = array(0);
  96          $class = new \ReflectionClass($this);
  97          $dumpItem = $class->getMethod('dumpItem');
  98          $dumpItem->setAccessible(true);
  99          $data = $this->getRawData();
 100          $args = array($dumper, new Cursor(), &$refs, $data[$this->position][$this->key]);
 101          $dumpItem->invokeArgs($this, $args);
 102      }
 103  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer