コード例 #1
0
ファイル: dump.php プロジェクト: jiangyu7408/notification
 /**
  * @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);
 }
コード例 #2
0
ファイル: DumperServiceProvider.php プロジェクト: bolt/bolt
 /**
  * {@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;
     });
 }
コード例 #3
0
ファイル: Dump.php プロジェクト: cawaphp/cawa
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     $handler = VarDumper::setHandler();
     dump($event->format());
     VarDumper::setHandler($handler);
     return true;
 }
コード例 #4
0
    /**
     * @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);
    }
コード例 #5
0
ファイル: DumpListener.php プロジェクト: Gladhon/symfony
 public function configure()
 {
     $cloner = $this->cloner;
     $dumper = $this->dumper;
     VarDumper::setHandler(function ($var) use($cloner, $dumper) {
         $dumper->dump($cloner->cloneVar($var));
     });
 }
コード例 #6
0
ファイル: Dumper.php プロジェクト: groovey/framework
 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));
     });
 }
コード例 #7
0
 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));
     });
 }
コード例 #8
0
 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);
     });
 }
コード例 #9
0
ファイル: DumpListener.php プロジェクト: vomasmic/symfony
 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);
         });
     }
 }
コード例 #10
0
ファイル: DebugBundle.php プロジェクト: vomasmic/symfony
 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);
         });
     }
 }
コード例 #11
0
ファイル: functions.php プロジェクト: cawaphp/cawa
 /**
  * @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();
 }
コード例 #12
0
 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;
     }
 }
コード例 #13
0
ファイル: DumperServiceProvider.php プロジェクト: d-m-/bolt
 /**
  * {@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;
     });
 }
コード例 #14
0
ファイル: BoltTwigHelpersTest.php プロジェクト: annejan/bolt
 /**
  * Override Symfony's default handler to get the output
  */
 protected function stubVarDumper()
 {
     VarDumper::setHandler(function ($var) {
         return $var;
     });
 }
コード例 #15
0
ファイル: DumpListenerTest.php プロジェクト: vomasmic/symfony
 private function getDumpHandler()
 {
     $prevDumper = VarDumper::setHandler('var_dump');
     VarDumper::setHandler($prevDumper);
     return $prevDumper;
 }