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