Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\VarDumper; Chris@0: Chris@0: use Symfony\Component\VarDumper\Cloner\VarCloner; Chris@0: use Symfony\Component\VarDumper\Dumper\CliDumper; Chris@0: use Symfony\Component\VarDumper\Dumper\HtmlDumper; Chris@0: Chris@0: // Load the global dump() function Chris@0: require_once __DIR__.'/Resources/functions/dump.php'; Chris@0: Chris@0: /** Chris@0: * @author Nicolas Grekas
Chris@0: */ Chris@0: class VarDumper Chris@0: { Chris@0: private static $handler; Chris@0: Chris@0: public static function dump($var) Chris@0: { Chris@0: if (null === self::$handler) { Chris@0: $cloner = new VarCloner(); Chris@17: $dumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliDumper() : new HtmlDumper(); Chris@0: self::$handler = function ($var) use ($cloner, $dumper) { Chris@0: $dumper->dump($cloner->cloneVar($var)); Chris@0: }; Chris@0: } Chris@0: Chris@17: return \call_user_func(self::$handler, $var); Chris@0: } Chris@0: Chris@0: public static function setHandler(callable $callable = null) Chris@0: { Chris@0: $prevHandler = self::$handler; Chris@0: self::$handler = $callable; Chris@0: Chris@0: return $prevHandler; Chris@0: } Chris@0: }