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;
14 use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
19 * Children of this class must store the collected data in the data property.
21 * @author Fabien Potencier <fabien@symfony.com>
22 * @author Bernhard Schussek <bschussek@symfony.com>
24 abstract class DataCollector implements DataCollectorInterface, \Serializable
26 protected $data = array();
31 private $valueExporter;
33 public function serialize()
35 return serialize($this->data);
38 public function unserialize($data)
40 $this->data = unserialize($data);
44 * Converts a PHP variable to a string.
46 * @param mixed $var A PHP variable
48 * @return string The string representation of the variable
50 protected function varToString($var)
52 if (null === $this->valueExporter) {
53 $this->valueExporter = new ValueExporter();
56 return $this->valueExporter->exportValue($var);