Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009-2012 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
 * Represents a template filter.
14
 *
15
 * @author Fabien Potencier <fabien@symfony.com>
16
 */
17
class Twig_SimpleFilter
18
{
19
    protected $name;
20
    protected $callable;
21
    protected $options;
22
    protected $arguments = array();
23

    
24
    public function __construct($name, $callable, array $options = array())
25
    {
26
        $this->name = $name;
27
        $this->callable = $callable;
28
        $this->options = array_merge(array(
29
            'needs_environment' => false,
30
            'needs_context' => false,
31
            'is_variadic' => false,
32
            'is_safe' => null,
33
            'is_safe_callback' => null,
34
            'pre_escape' => null,
35
            'preserves_safety' => null,
36
            'node_class' => 'Twig_Node_Expression_Filter',
37
            'deprecated' => false,
38
            'alternative' => null,
39
        ), $options);
40
    }
41

    
42
    public function getName()
43
    {
44
        return $this->name;
45
    }
46

    
47
    public function getCallable()
48
    {
49
        return $this->callable;
50
    }
51

    
52
    public function getNodeClass()
53
    {
54
        return $this->options['node_class'];
55
    }
56

    
57
    public function setArguments($arguments)
58
    {
59
        $this->arguments = $arguments;
60
    }
61

    
62
    public function getArguments()
63
    {
64
        return $this->arguments;
65
    }
66

    
67
    public function needsEnvironment()
68
    {
69
        return $this->options['needs_environment'];
70
    }
71

    
72
    public function needsContext()
73
    {
74
        return $this->options['needs_context'];
75
    }
76

    
77
    public function getSafe(Twig_Node $filterArgs)
78
    {
79
        if (null !== $this->options['is_safe']) {
80
            return $this->options['is_safe'];
81
        }
82

    
83
        if (null !== $this->options['is_safe_callback']) {
84
            return call_user_func($this->options['is_safe_callback'], $filterArgs);
85
        }
86
    }
87

    
88
    public function getPreservesSafety()
89
    {
90
        return $this->options['preserves_safety'];
91
    }
92

    
93
    public function getPreEscape()
94
    {
95
        return $this->options['pre_escape'];
96
    }
97

    
98
    public function isVariadic()
99
    {
100
        return $this->options['is_variadic'];
101
    }
102

    
103
    public function isDeprecated()
104
    {
105
        return (bool) $this->options['deprecated'];
106
    }
107

    
108
    public function getDeprecatedVersion()
109
    {
110
        return $this->options['deprecated'];
111
    }
112

    
113
    public function getAlternative()
114
    {
115
        return $this->options['alternative'];
116
    }
117
}
(30-30/43)