Completed
Pull Request — master (#40)
by Arman
03:47
created

export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
use Symfony\Component\VarDumper\Cloner\AbstractCloner;
4
use Symfony\Component\VarDumper\Cloner\VarCloner;
5
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
6
use Symfony\Component\VarDumper\Dumper\CliDumper;
7
use Symfony\Component\VarExporter\VarExporter;
8
9
if (!function_exists('out')) {
10
11
    /**
12
     * Outputs the dump of teh variable
13
     * @param mixed $var
14
     * @param bool $die
15
     * @throws ErrorException
16
     */
17
    function out($var, $die = false)
18
    {
19
20
        $dumperStyle = [
21
            'default' => 'background-color:#FFFFFF; color:#FF8400; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
22
            'public' => 'color:#222222',
23
            'protected' => 'color:#222222',
24
            'private' => 'color:#222222'
25
        ];
26
27
        if (config()->get('debug') && !$die) {
28
            $debugOutput = (array)session()->get('_qt_debug_output') ?? [];
29
            array_push($debugOutput, $var);
30
            session()->set('_qt_debug_output', $debugOutput);
31
        } else {
32
            $cloner = new VarCloner();
33
            $dumper = PHP_SAPI === 'cli' ? new CliDumper() : new HtmlDumper();
34
            $dumper->setStyles($dumperStyle);
35
            $dumper->dump($cloner->cloneVar($var));
36
        }
37
38
        if ($die) {
39
            die;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
40
        }
41
    }
42
43
    if (!function_exists('export')) {
44
45
        /**
46
         * Exports the variable
47
         * @param mixed $var
48
         * @return string
49
         * @throws \Symfony\Component\VarExporter\Exception\ExceptionInterface
50
         */
51
        function export($var)
52
        {
53
            return VarExporter::export($var);
54
        }
55
    }
56
57
}