Sen descrición

ContextualizedDumper.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }