Drupal investigation

VarDumper.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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)
  34. {
  35. if (null !== $callable && !is_callable($callable, true)) {
  36. throw new \InvalidArgumentException('Invalid PHP callback.');
  37. }
  38. $prevHandler = self::$handler;
  39. self::$handler = $callable;
  40. return $prevHandler;
  41. }
  42. }