1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of Twig.
|
5
|
*
|
6
|
* (c) 2011 Fabien Potencier
|
7
|
*
|
8
|
* For the full copyright and license information, please view the LICENSE
|
9
|
* file that was distributed with this source code.
|
10
|
*/
|
11
|
class Twig_Extension_Debug extends Twig_Extension
|
12
|
{
|
13
|
/**
|
14
|
* Returns a list of global functions to add to the existing list.
|
15
|
*
|
16
|
* @return array An array of global functions
|
17
|
*/
|
18
|
public function getFunctions()
|
19
|
{
|
20
|
// dump is safe if var_dump is overriden by xdebug
|
21
|
$isDumpOutputHtmlSafe = extension_loaded('xdebug') && (false === get_cfg_var('xdebug.overload_var_dump') || get_cfg_var('xdebug.overload_var_dump')) && get_cfg_var('html_errors');
|
22
|
|
23
|
return array(
|
24
|
'dump' => new Twig_Function_Function('twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)),
|
25
|
);
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Returns the name of the extension.
|
30
|
*
|
31
|
* @return string The extension name
|
32
|
*/
|
33
|
public function getName()
|
34
|
{
|
35
|
return 'debug';
|
36
|
}
|
37
|
}
|
38
|
|
39
|
function twig_var_dump(Twig_Environment $env, $context)
|
40
|
{
|
41
|
if (!$env->isDebug()) {
|
42
|
return;
|
43
|
}
|
44
|
|
45
|
ob_start();
|
46
|
|
47
|
$count = func_num_args();
|
48
|
if (2 === $count) {
|
49
|
$vars = array();
|
50
|
foreach ($context as $key => $value) {
|
51
|
if (!$value instanceof Twig_Template) {
|
52
|
$vars[$key] = $value;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
var_dump($vars);
|
57
|
} else {
|
58
|
for ($i = 2; $i < $count; $i++) {
|
59
|
var_dump(func_get_arg($i));
|
60
|
}
|
61
|
}
|
62
|
|
63
|
return ob_get_clean();
|
64
|
}
|