Passed
Push — dependabot/composer/doctrine/d... ( bc1a80...bcc5a8 )
by
unknown
47:19 queued 41:28
created

src/Frontend/Core/Engine/FormNode.php (1 issue)

1
<?php
2
3
namespace Frontend\Core\Engine;
4
5
/**
6
 * Twig node for writing out the compiled representation of an opeing form tag.
7
 */
8
class FormNode extends \Twig_Node
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Node has been deprecated: since Twig 2.7, use "Twig\Node\Node" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
class FormNode extends /** @scrutinizer ignore-deprecated */ \Twig_Node
Loading history...
9
{
10
    /**
11
     * @var string Template variable holding the form.
12
     */
13
    private $form;
14
15
    /**
16
     * @param string $form The name of the template variable to which the form is assigned
17
     * @param int $lineNumber
18
     * @param string $tag
19
     */
20
    public function __construct(string $form, int $lineNumber, string $tag)
21
    {
22
        parent::__construct([], [], $lineNumber, $tag);
23
        $this->form = $form;
24
    }
25
26
    /**
27
     * @param \Twig_Compiler $compiler
28
     */
29
    public function compile(\Twig_Compiler $compiler): void
30
    {
31
        // Set some string representations to make the code writing via the
32
        // compiler a bit more readable. ("a bit")
33
        $form = "\$context['form_{$this->form}']";
34
        $formAction = $form . '->getAction()';
35
        $formMethod = $form . '->getMethod()';
36
        $formName = $form . '->getName()';
37
        $formToken = $form . '->getToken()';
38
        $formUseToken = $form . '->getUseToken()';
39
        $formParamsHtml = $form . '->getParametersHTML()';
40
        $formAttrAction = ' action="\', ' . $formAction . ', \'"';
41
        $formAttrMethod = ' method="\', ' . $formMethod . ', \'"';
42
        $hiddenFormName = '<input type="hidden" name="form" value="\', ' . $formName . ', \'" id="form\', ucfirst(' . $formName . '), \'" />';
43
        $hiddenFormToken = '<input type="hidden" name="form_token" value="\', ' . $formToken . ', \'" id="formToken\', ucfirst(' . $formName . '), \'" />';
44
45
        $compiler
46
            ->addDebugInfo($this)
47
48
            ->write('echo \'<form')
49
            ->raw($formAttrMethod)
50
            ->raw($formAttrAction)
51
            ->raw("', ")
52
            ->raw(' ' . $formParamsHtml)
53
            ->raw(', \'')
54
            ->raw('>\'')
55
            ->raw(";\n")
56
57
            ->write("echo '$hiddenFormName';\n")
58
            ->write("if($formUseToken) echo '$hiddenFormToken';")
59
        ;
60
    }
61
}
62