Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
definenode
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 compile
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @copyright Portions (c) 2009 Fabien Potencier, Armin Ronacher
8* @license GNU General Public License, version 2 (GPL-2.0)
9*
10* For full copyright and license information, please see
11* the docs/CREDITS.txt file.
12*
13*/
14
15namespace phpbb\template\twig\node;
16
17class definenode extends \Twig\Node\Node
18{
19    public function __construct($capture, \Twig\Node\Node $name, \Twig\Node\Node $value, $lineno, $tag = null)
20    {
21        parent::__construct(array('name' => $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag);
22    }
23
24    /**
25    * Compiles the node to PHP.
26    *
27    * @param \Twig\Compiler A Twig\Compiler instance
28    */
29    public function compile(\Twig\Compiler $compiler)
30    {
31        $compiler->addDebugInfo($this);
32
33        if ($this->getAttribute('capture'))
34        {
35            $compiler
36                ->write("ob_start();\n")
37                ->subcompile($this->getNode('value'))
38            ;
39
40            $compiler->write("\$value = ('' === \$value = ob_get_clean()) ? '' : new \Twig\Markup(\$value, \$this->env->getCharset());\n");
41        }
42        else
43        {
44            $compiler
45                ->write("\$value = ")
46                ->subcompile($this->getNode('value'))
47                ->raw(";\n")
48            ;
49        }
50
51        $compiler
52            ->write("\$context['definition']->set('")
53            ->raw($this->getNode('name')->getAttribute('name'))
54            ->raw("', \$value);\n")
55        ;
56    }
57}