/** * @param mixed $var */ function appendLog($var) { static $handler = null; if ($handler === null) { $logDir = LOG_DIR; assert(is_dir($logDir), 'log dir "' . $logDir . '" must be a dir'); $logDir .= '/' . date('Ymd'); if (!is_dir($logDir)) { $success = mkdir($logDir); assert($success, 'log dir create failed: ' . $logDir . ': ' . json_encode(error_get_last())); } $logFile = $logDir . '/' . GAME_VERSION; $cloner = new VarCloner(); $dumper = new CliDumper($logFile); $handler = function ($var) use($cloner, $dumper) { $dumper->dump($cloner->cloneVar($var)); }; } $origHandler = VarDumper::setHandler($handler); VarDumper::dump(date('c')); foreach (func_get_args() as $var) { VarDumper::dump($var); } VarDumper::setHandler($origHandler); }
/** * {@inheritdoc} */ public function register(Application $app) { $app['dump'] = $app->protect(function ($var) use($app) { if (!$app['debug']) { return; } $app['dumper']->dump($app['dumper.cloner']->cloneVar($var)); }); VarDumper::setHandler(function ($var) use($app) { /* * Referencing $app['dump'] in anonymous function * so the closure can be replaced in $app without * breaking the reference here. */ return $app['dump']($var); }); $app['dumper'] = $app->share(function ($app) { return PHP_SAPI === 'cli' ? $app['dumper.cli'] : $app['dumper.html']; }); $app['dumper.cli'] = $app->share(function () { return new CliDumper(); }); $app['dumper.html'] = $app->share(function () { return new HtmlDumper(); }); $app['dumper.cloner'] = $app->share(function () { $cloner = new VarCloner(); $cloner->addCasters(Caster\FilesystemCasters::getCasters()); return $cloner; }); }
/** * {@inheritdoc} */ protected function send(Event $event) : bool { $handler = VarDumper::setHandler(); dump($event->format()); VarDumper::setHandler($handler); return true; }
/** * @dataProvider getDumpTags */ public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped) { $extension = new DumpExtension(new VarCloner()); $twig = new \Twig_Environment(new \Twig_Loader_String(), array( 'debug' => $debug, 'cache' => false, 'optimizations' => 0, )); $twig->addExtension($extension); $dumped = null; $exception = null; $prevDumper = VarDumper::setHandler(function ($var) use (&$dumped) {$dumped = $var;}); try { $this->assertEquals($expectedOutput, $twig->render($template)); } catch (\Exception $exception) { } VarDumper::setHandler($prevDumper); if (null !== $exception) { throw $exception; } $this->assertSame($expectedDumped, $dumped); }
public function configure() { $cloner = $this->cloner; $dumper = $this->dumper; VarDumper::setHandler(function ($var) use($cloner, $dumper) { $dumper->dump($cloner->cloneVar($var)); }); }
public function boot(Application $app) { VarDumper::setHandler(function ($var) { $cloner = new VarCloner(); $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper(); $dumper->dump($cloner->cloneVar($var)); }); }
public function boot(Application $app) { // 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) { $dumper = new CliDumper(); $dumper->dump($app['var_dumper.cloner']->cloneVar($var)); }); }
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); }); }
public function configure() { if ($this->container) { $container = $this->container; $dumper = $this->dumper; $this->container = null; VarDumper::setHandler(function ($var) use($container, $dumper) { $dumper = $container->get($dumper); $cloner = $container->get('var_dumper.cloner'); $handler = function ($var) use($dumper, $cloner) { $dumper->dump($cloner->cloneVar($var)); }; VarDumper::setHandler($handler); $handler($var); }); } }
public function boot() { if ($this->container->getParameter('kernel.debug')) { $container = $this->container; // 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($container) { $dumper = new CliDumper(); $cloner = $container->get('var_dumper.cloner'); $handler = function ($var) use($dumper, $cloner) { $dumper->dump($cloner->cloneVar($var)); }; VarDumper::setHandler($handler); $handler($var); }); } }
/** * @param mixed $vars */ function systrace(...$vars) { openlog('php-debug', LOG_PID, LOG_USER); $cloner = new VarCloner(); $dumper = new \Symfony\Component\VarDumper\Dumper\CliDumper(); $dumper::$defaultColors = true; $handler = function ($var) use($cloner, $dumper) { $dumper->dump($cloner->cloneVar($var), function ($line, $depth, $indentPad) { syslog(LOG_DEBUG, str_repeat($indentPad, $depth < 0 ? 0 : $depth) . $line); }); }; $prevHandler = VarDumper::setHandler($handler); if (sizeof($vars) == 1) { VarDumper::dump($vars[0]); } else { VarDumper::dump($vars); } VarDumper::setHandler($prevHandler); closelog(); }
public function testConfigure() { $prevDumper = VarDumper::setHandler('var_dump'); VarDumper::setHandler($prevDumper); $cloner = new MockCloner(); $dumper = new MockDumper(); ob_start(); $exception = null; $listener = new DumpListener($cloner, $dumper); try { $listener->configure(); VarDumper::dump('foo'); VarDumper::dump('bar'); $this->assertSame('+foo-+bar-', ob_get_clean()); } catch (\Exception $exception) { } VarDumper::setHandler($prevDumper); if (null !== $exception) { throw $exception; } }
/** * {@inheritdoc} */ public function register(Application $app) { $app['dump'] = $app->protect(function ($var) use($app) { $app['dumper']->dump($app['dumper.cloner']->cloneVar($var)); }); VarDumper::setHandler($app['dump']); $app['dumper'] = $app->share(function ($app) { return PHP_SAPI === 'cli' ? $app['dumper.cli'] : $app['dumper.html']; }); $app['dumper.cli'] = $app->share(function () { return new CliDumper(); }); $app['dumper.html'] = $app->share(function () { return new HtmlDumper(); }); $app['dumper.cloner'] = $app->share(function () { $cloner = new VarCloner(); $cloner->addCasters(Caster\FilesystemCasters::getCasters()); return $cloner; }); }
/** * Override Symfony's default handler to get the output */ protected function stubVarDumper() { VarDumper::setHandler(function ($var) { return $var; }); }
private function getDumpHandler() { $prevDumper = VarDumper::setHandler('var_dump'); VarDumper::setHandler($prevDumper); return $prevDumper; }