Created
June 21, 2016 10:23
-
-
Save widnyana/38e4b506be37cc1fe2a2eb7f3dfcad96 to your computer and use it in GitHub Desktop.
Silex 1.3 VarDumperServiceProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers; | |
| use Silex\Application; | |
| use Silex\ServiceProviderInterface; | |
| use Symfony\Component\VarDumper\Cloner\VarCloner; | |
| use Symfony\Component\VarDumper\Dumper\CliDumper; | |
| use Symfony\Component\VarDumper\VarDumper; | |
| class VarDumperServiceProvider implements ServiceProviderInterface { | |
| /** | |
| * Registers services on the given app. | |
| * | |
| * This method should only be used to configure services and parameters. | |
| * It should not get services. | |
| * @param Application $app | |
| */ | |
| public function register(Application $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; | |
| } | |
| /** | |
| * Bootstraps the application. | |
| * | |
| * This method is called after all services are registered | |
| * and should be used for "dynamic" configuration (whenever | |
| * a service must be requested). | |
| * @param Application $app | |
| */ | |
| 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); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment