4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DataCollector\Util;
14 @trigger_error('The '.__NAMESPACE__.'\ValueExporter class is deprecated since version 3.2 and will be removed in 4.0. Use the VarDumper component instead.', E_USER_DEPRECATED);
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 * @deprecated since version 3.2, to be removed in 4.0. Use the VarDumper component instead.
24 * Converts a PHP value to a string.
26 * @param mixed $value The PHP value
27 * @param int $depth only for internal usage
28 * @param bool $deep only for internal usage
30 * @return string The string representation of the given value
32 public function exportValue($value, $depth = 1, $deep = false)
34 if ($value instanceof \__PHP_Incomplete_Class) {
35 return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
38 if (is_object($value)) {
39 if ($value instanceof \DateTimeInterface) {
40 return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ATOM));
43 return sprintf('Object(%s)', get_class($value));
46 if (is_array($value)) {
51 $indent = str_repeat(' ', $depth);
54 foreach ($value as $k => $v) {
58 $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
62 return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
65 $s = sprintf('[%s]', implode(', ', $a));
67 if (80 > strlen($s)) {
71 return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a));
74 if (is_resource($value)) {
75 return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
78 if (null === $value) {
82 if (false === $value) {
86 if (true === $value) {
90 return (string) $value;
93 private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
95 $array = new \ArrayObject($value);
97 return $array['__PHP_Incomplete_Class_Name'];