[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/DataCollector/Util/ -> ValueExporter.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\HttpKernel\DataCollector\Util;
  13  
  14  @trigger_error('The '.__NAMESPACE__.'\ValueExporter class is deprecated since Symfony 3.2 and will be removed in 4.0. Use the VarDumper component instead.', E_USER_DEPRECATED);
  15  
  16  /**
  17   * @author Bernhard Schussek <bschussek@gmail.com>
  18   *
  19   * @deprecated since version 3.2, to be removed in 4.0. Use the VarDumper component instead.
  20   */
  21  class ValueExporter
  22  {
  23      /**
  24       * Converts a PHP value to a string.
  25       *
  26       * @param mixed $value The PHP value
  27       * @param int   $depth Only for internal usage
  28       * @param bool  $deep  Only for internal usage
  29       *
  30       * @return string The string representation of the given value
  31       */
  32      public function exportValue($value, $depth = 1, $deep = false)
  33      {
  34          if ($value instanceof \__PHP_Incomplete_Class) {
  35              return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
  36          }
  37  
  38          if (\is_object($value)) {
  39              if ($value instanceof \DateTimeInterface) {
  40                  return sprintf('Object(%s) - %s', \get_class($value), $value->format(\DateTime::ATOM));
  41              }
  42  
  43              return sprintf('Object(%s)', \get_class($value));
  44          }
  45  
  46          if (\is_array($value)) {
  47              if (empty($value)) {
  48                  return '[]';
  49              }
  50  
  51              $indent = str_repeat('  ', $depth);
  52  
  53              $a = [];
  54              foreach ($value as $k => $v) {
  55                  if (\is_array($v)) {
  56                      $deep = true;
  57                  }
  58                  $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
  59              }
  60  
  61              if ($deep) {
  62                  return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat('  ', $depth - 1));
  63              }
  64  
  65              $s = sprintf('[%s]', implode(', ', $a));
  66  
  67              if (80 > \strlen($s)) {
  68                  return $s;
  69              }
  70  
  71              return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a));
  72          }
  73  
  74          if (\is_resource($value)) {
  75              return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
  76          }
  77  
  78          if (null === $value) {
  79              return 'null';
  80          }
  81  
  82          if (false === $value) {
  83              return 'false';
  84          }
  85  
  86          if (true === $value) {
  87              return 'true';
  88          }
  89  
  90          return (string) $value;
  91      }
  92  
  93      private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
  94      {
  95          $array = new \ArrayObject($value);
  96  
  97          return $array['__PHP_Incomplete_Class_Name'];
  98      }
  99  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1