You are here

class ValueExporter in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/DataCollector/Util/ValueExporter.php \Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter

Expanded class hierarchy of ValueExporter

2 files declare their use of ValueExporter
DataCollector.php in vendor/symfony/http-kernel/DataCollector/DataCollector.php
ValueExporterTest.php in vendor/symfony/http-kernel/Tests/DataCollector/Util/ValueExporterTest.php

File

vendor/symfony/http-kernel/DataCollector/Util/ValueExporter.php, line 17

Namespace

Symfony\Component\HttpKernel\DataCollector\Util
View source
class ValueExporter {

  /**
   * Converts a PHP value to a string.
   *
   * @param mixed $value The PHP value
   * @param int   $depth only for internal usage
   * @param bool  $deep  only for internal usage
   *
   * @return string The string representation of the given value
   */
  public function exportValue($value, $depth = 1, $deep = false) {
    if (is_object($value)) {
      if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
        return sprintf('Object(%s) - %s', get_class($value), $value
          ->format(\DateTime::ISO8601));
      }
      return sprintf('Object(%s)', get_class($value));
    }
    if (is_array($value)) {
      if (empty($value)) {
        return '[]';
      }
      $indent = str_repeat('  ', $depth);
      $a = array();
      foreach ($value as $k => $v) {
        if (is_array($v)) {
          $deep = true;
        }
        $a[] = sprintf('%s => %s', $k, $this
          ->exportValue($v, $depth + 1, $deep));
      }
      if ($deep) {
        return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat('  ', $depth - 1));
      }
      return sprintf('[%s]', implode(', ', $a));
    }
    if (is_resource($value)) {
      return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
    }
    if (null === $value) {
      return 'null';
    }
    if (false === $value) {
      return 'false';
    }
    if (true === $value) {
      return 'true';
    }
    return (string) $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ValueExporter::exportValue public function Converts a PHP value to a string.