ServerDumper.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 $connection;
  22. /**
  23. * @param string $host The server host
  24. * @param DataDumperInterface|null $wrappedDumper A wrapped instance used whenever we failed contacting the server
  25. * @param ContextProviderInterface[] $contextProviders Context providers indexed by context name
  26. */
  27. public function __construct(
  28. string $host,
  29. private ?DataDumperInterface $wrappedDumper = null,
  30. array $contextProviders = [],
  31. ) {
  32. $this->connection = new Connection($host, $contextProviders);
  33. }
  34. public function getContextProviders(): array
  35. {
  36. return $this->connection->getContextProviders();
  37. }
  38. public function dump(Data $data): ?string
  39. {
  40. if (!$this->connection->write($data) && $this->wrappedDumper) {
  41. return $this->wrappedDumper->dump($data);
  42. }
  43. return null;
  44. }
  45. }