AjaxDataCollector.php
2 years ago
ConfigDataCollector.php
1 year ago
DataCollector.php
2 years ago
DataCollectorInterface.php
2 years ago
DumpDataCollector.php
1 year ago
EventDataCollector.php
2 years ago
ExceptionDataCollector.php
2 years ago
LateDataCollectorInterface.php
2 years ago
LoggerDataCollector.php
1 year ago
MemoryDataCollector.php
1 year ago
RequestDataCollector.php
1 year ago
RouterDataCollector.php
1 year ago
TimeDataCollector.php
1 year ago
DataCollector.php
109 lines
| 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 | namespace Matomo\Dependencies\Symfony\Component\HttpKernel\DataCollector; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\VarDumper\Caster\CutStub; |
| 14 | use Matomo\Dependencies\Symfony\Component\VarDumper\Caster\ReflectionCaster; |
| 15 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\ClonerInterface; |
| 16 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\Data; |
| 17 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\Stub; |
| 18 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\VarCloner; |
| 19 | /** |
| 20 | * DataCollector. |
| 21 | * |
| 22 | * Children of this class must store the collected data in the data property. |
| 23 | * |
| 24 | * @author Fabien Potencier <fabien@symfony.com> |
| 25 | * @author Bernhard Schussek <bschussek@symfony.com> |
| 26 | */ |
| 27 | abstract class DataCollector implements DataCollectorInterface |
| 28 | { |
| 29 | /** |
| 30 | * @var array|Data |
| 31 | */ |
| 32 | protected $data = []; |
| 33 | /** |
| 34 | * @var ClonerInterface |
| 35 | */ |
| 36 | private $cloner; |
| 37 | /** |
| 38 | * Converts the variable into a serializable Data instance. |
| 39 | * |
| 40 | * This array can be displayed in the template using |
| 41 | * the VarDumper component. |
| 42 | * |
| 43 | * @param mixed $var |
| 44 | * |
| 45 | * @return Data |
| 46 | */ |
| 47 | protected function cloneVar($var) |
| 48 | { |
| 49 | if ($var instanceof Data) { |
| 50 | return $var; |
| 51 | } |
| 52 | if (null === $this->cloner) { |
| 53 | $this->cloner = new VarCloner(); |
| 54 | $this->cloner->setMaxItems(-1); |
| 55 | $this->cloner->addCasters($this->getCasters()); |
| 56 | } |
| 57 | return $this->cloner->cloneVar($var); |
| 58 | } |
| 59 | /** |
| 60 | * @return callable[] The casters to add to the cloner |
| 61 | */ |
| 62 | protected function getCasters() |
| 63 | { |
| 64 | $casters = ['*' => function ($v, array $a, Stub $s, $isNested) { |
| 65 | if (!$v instanceof Stub) { |
| 66 | $b = $a; |
| 67 | foreach ($a as $k => $v) { |
| 68 | if (!\is_object($v) || $v instanceof \DateTimeInterface || $v instanceof Stub) { |
| 69 | continue; |
| 70 | } |
| 71 | try { |
| 72 | $a[$k] = $s = new CutStub($v); |
| 73 | if ($b[$k] === $s) { |
| 74 | // we've hit a non-typed reference |
| 75 | $a[$k] = $v; |
| 76 | } |
| 77 | } catch (\TypeError $e) { |
| 78 | // we've hit a typed reference |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | return $a; |
| 83 | }] + ReflectionCaster::UNSET_CLOSURE_FILE_INFO; |
| 84 | return $casters; |
| 85 | } |
| 86 | /** |
| 87 | * @return array |
| 88 | */ |
| 89 | public function __sleep() |
| 90 | { |
| 91 | return ['data']; |
| 92 | } |
| 93 | public function __wakeup() |
| 94 | { |
| 95 | } |
| 96 | /** |
| 97 | * @internal to prevent implementing \Serializable |
| 98 | */ |
| 99 | protected final function serialize() |
| 100 | { |
| 101 | } |
| 102 | /** |
| 103 | * @internal to prevent implementing \Serializable |
| 104 | */ |
| 105 | protected final function unserialize($data) |
| 106 | { |
| 107 | } |
| 108 | } |
| 109 |