composer package updates
[openemr.git] / vendor / twig / twig / lib / Twig / Extension / Debug.php
blobd0cd1962be0d902002257b18c538c18360841eb4
1 <?php
3 /*
4 * This file is part of Twig.
6 * (c) Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 /**
13 * @final
15 class Twig_Extension_Debug extends Twig_Extension
17 public function getFunctions()
19 // dump is safe if var_dump is overridden by xdebug
20 $isDumpOutputHtmlSafe = extension_loaded('xdebug')
21 // false means that it was not set (and the default is on) or it explicitly enabled
22 && (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
23 // false means that it was not set (and the default is on) or it explicitly enabled
24 // xdebug.overload_var_dump produces HTML only when html_errors is also enabled
25 && (false === ini_get('html_errors') || ini_get('html_errors'))
26 || 'cli' === PHP_SAPI
29 return array(
30 new Twig_SimpleFunction('dump', 'twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)),
34 public function getName()
36 return 'debug';
40 function twig_var_dump(Twig_Environment $env, $context)
42 if (!$env->isDebug()) {
43 return;
46 ob_start();
48 $count = func_num_args();
49 if (2 === $count) {
50 $vars = array();
51 foreach ($context as $key => $value) {
52 if (!$value instanceof Twig_Template) {
53 $vars[$key] = $value;
57 var_dump($vars);
58 } else {
59 for ($i = 2; $i < $count; ++$i) {
60 var_dump(func_get_arg($i));
64 return ob_get_clean();
67 class_alias('Twig_Extension_Debug', 'Twig\Extension\DebugExtension', false);