You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

2 years ago
  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. use Symfony\Component\VarDumper\Server\Connection;
  14. /**
  15. * ServerDumper forwards serialized Data clones to a server.
  16. *
  17. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  18. */
  19. class ServerDumper implements DataDumperInterface
  20. {
  21. private $connection;
  22. private $wrappedDumper;
  23. /**
  24. * @param string $host The server host
  25. * @param DataDumperInterface|null $wrappedDumper A wrapped instance used whenever we failed contacting the server
  26. * @param ContextProviderInterface[] $contextProviders Context providers indexed by context name
  27. */
  28. public function __construct(string $host, DataDumperInterface $wrappedDumper = null, array $contextProviders = [])
  29. {
  30. $this->connection = new Connection($host, $contextProviders);
  31. $this->wrappedDumper = $wrappedDumper;
  32. }
  33. public function getContextProviders(): array
  34. {
  35. return $this->connection->getContextProviders();
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function dump(Data $data)
  41. {
  42. if (!$this->connection->write($data) && $this->wrappedDumper) {
  43. $this->wrappedDumper->dump($data);
  44. }
  45. }
  46. }