Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2011 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
 * Checks if a variable is the exact same value as a constant.
14
 *
15
 * <pre>
16
 *  {% if post.status is constant('Post::PUBLISHED') %}
17
 *    the status attribute is exactly the same as Post::PUBLISHED
18
 *  {% endif %}
19
 * </pre>
20
 *
21
 * @package twig
22
 * @author  Fabien Potencier <fabien@symfony.com>
23
 */
24
class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
25
{
26
    public function compile(Twig_Compiler $compiler)
27
    {
28
        $compiler
29
            ->raw('(')
30
            ->subcompile($this->getNode('node'))
31
            ->raw(' === constant(')
32
            ->subcompile($this->getNode('arguments')->getNode(0))
33
            ->raw('))')
34
        ;
35
    }
36
}
(1-1/7)