-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathFallbackDumper.php
64 lines (56 loc) · 1.68 KB
/
FallbackDumper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace BeyondCode\DumpServer;
use Illuminate\Foundation\Console\CliDumper as LaravelCliDumper;
use Illuminate\Foundation\Http\HtmlDumper as LaravelHtmlDumper;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\CliDumper as SymfonyCliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper as SymfonyHtmlDumper;
class FallbackDumper
{
/**
* The base path of the application.
*
* @var string
*/
protected $basePath;
/**
* The compiled view path for the application.
*
* @var string
*/
protected $compiledViewPath;
/**
* FallbackDumper constructor.
*
* @param string $basePath
* @param string $compiledViewPath
* @return void
*/
public function __construct(string $basePath, string $compiledViewPath)
{
$this->basePath = $basePath;
$this->compiledViewPath = $compiledViewPath;
}
/**
* Dump a value with elegance.
*
* @param Data $data
* @return void
*/
public function dump(Data $data)
{
if (class_exists(LaravelCliDumper::class)) {
// Laravel 9+
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg'])
? new LaravelCliDumper(new ConsoleOutput, $this->basePath, $this->compiledViewPath)
: new LaravelHtmlDumper($this->basePath, $this->compiledViewPath);
$dumper->dumpWithSource($data);
} else {
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg'])
? new SymfonyCliDumper
: new SymfonyHtmlDumper;
$dumper->dump($data);
}
}
}