blob: 76384176ef026ae81c0c6c1378724ea456763716 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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
12namespace Symfony\Component\VarDumper\Dumper;
13
14use Symfony\Component\VarDumper\Cloner\Data;
15use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
16
17/**
18 * @author Kévin Thérage <therage.kevin@gmail.com>
19 */
20class ContextualizedDumper implements DataDumperInterface
21{
22 private $wrappedDumper;
23 private $contextProviders;
24
25 /**
26 * @param ContextProviderInterface[] $contextProviders
27 */
28 public function __construct(DataDumperInterface $wrappedDumper, array $contextProviders)
29 {
30 $this->wrappedDumper = $wrappedDumper;
31 $this->contextProviders = $contextProviders;
32 }
33
34 public function dump(Data $data)
35 {
36 $context = [];
37 foreach ($this->contextProviders as $contextProvider) {
38 $context[\get_class($contextProvider)] = $contextProvider->getContext();
39 }
40
41 $this->wrappedDumper->dump($data->withContext($context));
42 }
43}