Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
DumpServerServiceProvider
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 register
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Helpers;
6
7use Engelsystem\Config\Config;
8use Engelsystem\Container\ServiceProvider;
9use Symfony\Component\VarDumper\Cloner\VarCloner;
10use Symfony\Component\VarDumper\Dumper\CliDumper;
11use Symfony\Component\VarDumper\Dumper\ContextProvider\CliContextProvider;
12use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
13use Symfony\Component\VarDumper\Dumper\HtmlDumper;
14use Symfony\Component\VarDumper\Dumper\ServerDumper;
15use Symfony\Component\VarDumper\VarDumper;
16
17class DumpServerServiceProvider extends ServiceProvider
18{
19    public function register(): void
20    {
21        $app = $this->app;
22
23        /** @var Config $config */
24        $config = $app->get('config');
25        // setup var dump server to use for easier debugging
26        $varDumpServerConfig = $config->get('var_dump_server');
27
28        if (
29            !$varDumpServerConfig['enable']
30            || $config->get('environment') !== 'development'
31            || !class_exists(ServerDumper::class)
32        ) {
33            return;
34        }
35
36        $dumper = new ServerDumper(
37            'tcp://' . $varDumpServerConfig['host'] . ':' . $varDumpServerConfig['port'],
38            in_array(PHP_SAPI, ['cli', 'phpdbg']) ? $app->get(CliDumper::class) : $app->get(HtmlDumper::class),
39            [
40                'cli'    => new CliContextProvider(),
41                'source' => new SourceContextProvider(),
42            ]
43        );
44
45        $cloner = $app->get(VarCloner::class);
46
47        VarDumper::setHandler(
48            // @codeCoverageIgnoreStart
49            static function ($var) use ($cloner, $dumper): void {
50                $dumper->dump($cloner->cloneVar($var));
51            }
52            // @codeCoverageIgnoreEnd
53        );
54    }
55}