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;
15 * @author Bernhard Schussek <bschussek@gmail.com>
20 * Converts a PHP value to a string.
22 * @param mixed $value The PHP value
23 * @param int $depth only for internal usage
24 * @param bool $deep only for internal usage
26 * @return string The string representation of the given value
28 public function exportValue($value, $depth = 1, $deep = false)
30 if ($value instanceof \__PHP_Incomplete_Class) {
31 return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
34 if (is_object($value)) {
35 if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
36 return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ATOM));
39 return sprintf('Object(%s)', get_class($value));
42 if (is_array($value)) {
47 $indent = str_repeat(' ', $depth);
50 foreach ($value as $k => $v) {
54 $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
58 return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
61 return sprintf('[%s]', implode(', ', $a));
64 if (is_resource($value)) {
65 return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
68 if (null === $value) {
72 if (false === $value) {
76 if (true === $value) {
80 return (string) $value;
83 private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
85 $array = new \ArrayObject($value);
87 return $array['__PHP_Incomplete_Class_Name'];