ContextualizedDumper.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Dumper;
  11. use Symfony\Component\VarDumper\Cloner\Data;
  12. use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
  13. /**
  14. * @author Kévin Thérage <therage.kevin@gmail.com>
  15. */
  16. class ContextualizedDumper implements DataDumperInterface
  17. {
  18. private $wrappedDumper;
  19. private $contextProviders;
  20. /**
  21. * @param ContextProviderInterface[] $contextProviders
  22. */
  23. public function __construct(DataDumperInterface $wrappedDumper, array $contextProviders)
  24. {
  25. $this->wrappedDumper = $wrappedDumper;
  26. $this->contextProviders = $contextProviders;
  27. }
  28. public function dump(Data $data)
  29. {
  30. $context = [];
  31. foreach ($this->contextProviders as $contextProvider) {
  32. $context[\get_class($contextProvider)] = $contextProvider->getContext();
  33. }
  34. $this->wrappedDumper->dump($data->withContext($context));
  35. }
  36. }