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