AnnotationsNode::compile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 11
c 2
b 1
f 1
nc 1
nop 1
dl 0
loc 14
rs 9.9
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Bundle\FrameworkExtraBundle\Twig\Meta;
7
8
use Twig_Node;
9
use Twig_Compiler;
10
11
/**
12
 * Class AnnotationsNode
13
 *
14
 * @package Zicht\Bundle\FrameworkExtraBundle\Twig\Meta
15
 */
16
class AnnotationsNode extends Twig_Node
17
{
18
    /**
19
     * Compile
20
     *
21
     * @param Twig_Compiler $compiler
22
     */
23
    public function compile(Twig_Compiler $compiler)
24
    {
25
        $compiler->addDebugInfo($this);
26
27
        $compiler
28
            ->write('$parent = $context;')
29
            ->write('foreach ($this->env->getExtension(\'zicht_framework_extra\')->getAnnotationRegistry()->getAnnotations() as $annotation) {')
30
            ->indent()
31
                ->write('$context[\'name\'] = $annotation[\'name\'];')
32
                ->write('$context[\'value\'] = $annotation[\'value\'];')
33
                ->subcompile($this->getNode('body'))
34
            ->outdent()
35
            ->write('}');
36
        $compiler->write('$context = $parent;');
37
    }
38
}
39