VarDumper.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 = \in_array(\PHP_SAPI, array('cli', 'phpdbg'), true) ? 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. }