Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 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\VarDumper\Dumper; |
| 13 | |
| 14 | use Symfony\Component\VarDumper\Cloner\Data; |
| 15 | use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface; |
| 16 | |
| 17 | /** |
| 18 | * @author Kévin Thérage <therage.kevin@gmail.com> |
| 19 | */ |
| 20 | class ContextualizedDumper implements DataDumperInterface |
| 21 | { |
| 22 | private $wrappedDumper; |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 23 | private array $contextProviders; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 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 | } |