Version 1
[yaffs-website] / vendor / symfony / http-kernel / DataCollector / DataCollector.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\DataCollector;
13
14 use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
15
16 /**
17  * DataCollector.
18  *
19  * Children of this class must store the collected data in the data property.
20  *
21  * @author Fabien Potencier <fabien@symfony.com>
22  * @author Bernhard Schussek <bschussek@symfony.com>
23  */
24 abstract class DataCollector implements DataCollectorInterface, \Serializable
25 {
26     protected $data = array();
27
28     /**
29      * @var ValueExporter
30      */
31     private $valueExporter;
32
33     public function serialize()
34     {
35         return serialize($this->data);
36     }
37
38     public function unserialize($data)
39     {
40         $this->data = unserialize($data);
41     }
42
43     /**
44      * Converts a PHP variable to a string.
45      *
46      * @param mixed $var A PHP variable
47      *
48      * @return string The string representation of the variable
49      */
50     protected function varToString($var)
51     {
52         if (null === $this->valueExporter) {
53             $this->valueExporter = new ValueExporter();
54         }
55
56         return $this->valueExporter->exportValue($var);
57     }
58 }