d0cd1962be0d902002257b18c538c18360841eb4
[yaffs-website] / vendor / twig / twig / lib / Twig / Extension / Debug.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 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
12 /**
13  * @final
14  */
15 class Twig_Extension_Debug extends Twig_Extension
16 {
17     public function getFunctions()
18     {
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
27         ;
28
29         return array(
30             new Twig_SimpleFunction('dump', 'twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)),
31         );
32     }
33
34     public function getName()
35     {
36         return 'debug';
37     }
38 }
39
40 function twig_var_dump(Twig_Environment $env, $context)
41 {
42     if (!$env->isDebug()) {
43         return;
44     }
45
46     ob_start();
47
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;
54             }
55         }
56
57         var_dump($vars);
58     } else {
59         for ($i = 2; $i < $count; ++$i) {
60             var_dump(func_get_arg($i));
61         }
62     }
63
64     return ob_get_clean();
65 }
66
67 class_alias('Twig_Extension_Debug', 'Twig\Extension\DebugExtension', false);