[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 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 namespace Symfony\Bridge\Twig\Extension; 13 14 use Symfony\Bridge\Twig\TokenParser\DumpTokenParser; 15 use Symfony\Component\VarDumper\Cloner\ClonerInterface; 16 use Symfony\Component\VarDumper\Dumper\HtmlDumper; 17 use Twig\Environment; 18 use Twig\Extension\AbstractExtension; 19 use Twig\Template; 20 use Twig\TwigFunction; 21 22 /** 23 * Provides integration of the dump() function with Twig. 24 * 25 * @author Nicolas Grekas <p@tchwork.com> 26 */ 27 class DumpExtension extends AbstractExtension 28 { 29 private $cloner; 30 31 public function __construct(ClonerInterface $cloner) 32 { 33 $this->cloner = $cloner; 34 } 35 36 public function getFunctions() 37 { 38 return array( 39 new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)), 40 ); 41 } 42 43 public function getTokenParsers() 44 { 45 return array(new DumpTokenParser()); 46 } 47 48 public function getName() 49 { 50 return 'dump'; 51 } 52 53 public function dump(Environment $env, $context) 54 { 55 if (!$env->isDebug()) { 56 return; 57 } 58 59 if (2 === \func_num_args()) { 60 $vars = array(); 61 foreach ($context as $key => $value) { 62 if (!$value instanceof Template) { 63 $vars[$key] = $value; 64 } 65 } 66 67 $vars = array($vars); 68 } else { 69 $vars = \func_get_args(); 70 unset($vars[0], $vars[1]); 71 } 72 73 $dump = fopen('php://memory', 'r+b'); 74 $dumper = new HtmlDumper($dump, $env->getCharset()); 75 76 foreach ($vars as $value) { 77 $dumper->dump($this->cloner->cloneVar($value)); 78 } 79 rewind($dump); 80 81 return stream_get_contents($dump); 82 } 83 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |