Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\DataCollector\Util; Chris@0: Chris@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); Chris@0: Chris@0: /** Chris@0: * @author Bernhard Schussek Chris@0: * Chris@0: * @deprecated since version 3.2, to be removed in 4.0. Use the VarDumper component instead. Chris@0: */ Chris@0: class ValueExporter Chris@0: { Chris@0: /** Chris@0: * Converts a PHP value to a string. Chris@0: * Chris@0: * @param mixed $value The PHP value Chris@14: * @param int $depth Only for internal usage Chris@14: * @param bool $deep Only for internal usage Chris@0: * Chris@0: * @return string The string representation of the given value Chris@0: */ Chris@0: public function exportValue($value, $depth = 1, $deep = false) Chris@0: { Chris@0: if ($value instanceof \__PHP_Incomplete_Class) { Chris@0: return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value)); Chris@0: } Chris@0: Chris@17: if (\is_object($value)) { Chris@0: if ($value instanceof \DateTimeInterface) { Chris@17: return sprintf('Object(%s) - %s', \get_class($value), $value->format(\DateTime::ATOM)); Chris@0: } Chris@0: Chris@17: return sprintf('Object(%s)', \get_class($value)); Chris@0: } Chris@0: Chris@17: if (\is_array($value)) { Chris@0: if (empty($value)) { Chris@0: return '[]'; Chris@0: } Chris@0: Chris@0: $indent = str_repeat(' ', $depth); Chris@0: Chris@17: $a = []; Chris@0: foreach ($value as $k => $v) { Chris@17: if (\is_array($v)) { Chris@0: $deep = true; Chris@0: } Chris@0: $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep)); Chris@0: } Chris@0: Chris@0: if ($deep) { Chris@0: return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1)); Chris@0: } Chris@0: Chris@0: $s = sprintf('[%s]', implode(', ', $a)); Chris@0: Chris@17: if (80 > \strlen($s)) { Chris@0: return $s; Chris@0: } Chris@0: Chris@0: return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a)); Chris@0: } Chris@0: Chris@17: if (\is_resource($value)) { Chris@0: return sprintf('Resource(%s#%d)', get_resource_type($value), $value); Chris@0: } Chris@0: Chris@0: if (null === $value) { Chris@0: return 'null'; Chris@0: } Chris@0: Chris@0: if (false === $value) { Chris@0: return 'false'; Chris@0: } Chris@0: Chris@0: if (true === $value) { Chris@0: return 'true'; Chris@0: } Chris@0: Chris@0: return (string) $value; Chris@0: } Chris@0: Chris@0: private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value) Chris@0: { Chris@0: $array = new \ArrayObject($value); Chris@0: Chris@0: return $array['__PHP_Incomplete_Class_Name']; Chris@0: } Chris@0: }