Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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\VarDumper\Caster\CutStub;
15
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
16
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
17
use Symfony\Component\VarDumper\Cloner\Data;
18
use Symfony\Component\VarDumper\Cloner\Stub;
19
use Symfony\Component\VarDumper\Cloner\VarCloner;
20
 
21
/**
22
 * DataCollector.
23
 *
24
 * Children of this class must store the collected data in the data property.
25
 *
26
 * @author Fabien Potencier <fabien@symfony.com>
27
 * @author Bernhard Schussek <bschussek@symfony.com>
28
 */
29
abstract class DataCollector implements DataCollectorInterface
30
{
31
    /**
32
     * @var array|Data
33
     */
34
    protected $data = [];
35
 
36
    private ClonerInterface $cloner;
37
 
38
    /**
39
     * Converts the variable into a serializable Data instance.
40
     *
41
     * This array can be displayed in the template using
42
     * the VarDumper component.
43
     */
44
    protected function cloneVar(mixed $var): Data
45
    {
46
        if ($var instanceof Data) {
47
            return $var;
48
        }
49
        if (!isset($this->cloner)) {
50
            $this->cloner = new VarCloner();
51
            $this->cloner->setMaxItems(-1);
52
            $this->cloner->addCasters($this->getCasters());
53
        }
54
 
55
        return $this->cloner->cloneVar($var);
56
    }
57
 
58
    /**
59
     * @return callable[] The casters to add to the cloner
60
     */
61
    protected function getCasters()
62
    {
63
        $casters = [
64
            '*' => function ($v, array $a, Stub $s, $isNested) {
65
                if (!$v instanceof Stub) {
66
                    foreach ($a as $k => $v) {
67
                        if (\is_object($v) && !$v instanceof \DateTimeInterface && !$v instanceof Stub) {
68
                            $a[$k] = new CutStub($v);
69
                        }
70
                    }
71
                }
72
 
73
                return $a;
74
            },
75
        ] + ReflectionCaster::UNSET_CLOSURE_FILE_INFO;
76
 
77
        return $casters;
78
    }
79
 
80
    public function __sleep(): array
81
    {
82
        return ['data'];
83
    }
84
 
85
    public function __wakeup()
86
    {
87
    }
88
 
89
    /**
90
     * @internal to prevent implementing \Serializable
91
     */
92
    final protected function serialize()
93
    {
94
    }
95
 
96
    /**
97
     * @internal to prevent implementing \Serializable
98
     */
99
    final protected function unserialize(string $data)
100
    {
101
    }
102
}