forked from silexphp/Silex-Providers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVarDumperServiceProvider.php
58 lines (50 loc) · 1.64 KB
/
VarDumperServiceProvider.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
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
/**
* Symfony Var Dumper component Provider.
*
* @author Fabien Potencier <[email protected]>
*/
class VarDumperServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['var_dumper.cli_dumper'] = function ($app) {
return new CliDumper($app['var_dumper.dump_destination'], $app['charset']);
};
$app['var_dumper.cloner'] = function ($app) {
return new VarCloner();
};
$app['var_dumper.dump_destination'] = null;
}
public function boot(Application $app)
{
if (!$app['debug']) {
return;
}
// This code is here to lazy load the dump stack. This default
// configuration for CLI mode is overridden in HTTP mode on
// 'kernel.request' event
VarDumper::setHandler(function ($var) use ($app) {
VarDumper::setHandler($handler = function ($var) use ($app) {
$app['var_dumper.cli_dumper']->dump($app['var_dumper.cloner']->cloneVar($var));
});
$handler($var);
});
}
}