-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathDumpServerServiceProvider.php
More file actions
65 lines (52 loc) · 2.06 KB
/
DumpServerServiceProvider.php
File metadata and controls
65 lines (52 loc) · 2.06 KB
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
65
<?php
namespace BeyondCode\DumpServer;
use BeyondCode\DumpServer\FallbackDumper;
use Illuminate\Foundation\Console\CliDumper as LaravelCliDumper;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
use Symfony\Component\VarDumper\Server\Connection;
use Symfony\Component\VarDumper\Server\DumpServer;
use Symfony\Component\VarDumper\VarDumper;
class DumpServerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('debug-server.php'),
], 'config');
}
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'debug-server');
$this->app->bind('command.dumpserver', DumpServerCommand::class);
$this->commands([
'command.dumpserver',
]);
$host = $this->app['config']->get('debug-server.host');
$this->app->when(DumpServer::class)->needs('$host')->give($host);
$this->app->when(FallbackDumper::class)->needs('$basePath')->give(fn () => $this->app->basePath());
$this->app->when(FallbackDumper::class)->needs('$compiledViewPath')->give(fn () => $this->app['config']->get('view.compiled'));
$connection = new Connection($host, [
'request' => new RequestContextProvider($this->app['request']),
'source' => new SourceContextProvider('utf-8', base_path()),
]);
$fallbackDumper = class_exists(LaravelCliDumper::class)
? $this->app->make(FallbackDumper::class)
: null;
VarDumper::setHandler(function ($var) use ($connection, $fallbackDumper) {
$this->app->makeWith(Dumper::class, ['connection' => $connection, 'fallbackDumper' => $fallbackDumper])->dump($var);
});
}
}