菜谱项目

VarDumper.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper;
  11. use Symfony\Component\VarDumper\Cloner\VarCloner;
  12. use Symfony\Component\VarDumper\Dumper\CliDumper;
  13. use Symfony\Component\VarDumper\Dumper\HtmlDumper;
  14. // Load the global dump() function
  15. require_once __DIR__.'/Resources/functions/dump.php';
  16. /**
  17. * @author Nicolas Grekas <p@tchwork.com>
  18. */
  19. class VarDumper
  20. {
  21. private static $handler;
  22. public static function dump($var)
  23. {
  24. if (null === self::$handler) {
  25. $cloner = new VarCloner();
  26. $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
  27. self::$handler = function ($var) use ($cloner, $dumper) {
  28. $dumper->dump($cloner->cloneVar($var));
  29. };
  30. }
  31. return call_user_func(self::$handler, $var);
  32. }
  33. public static function setHandler(callable $callable = null)
  34. {
  35. $prevHandler = self::$handler;
  36. self::$handler = $callable;
  37. return $prevHandler;
  38. }
  39. }