Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 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
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
abstract class Twig_Filter implements Twig_FilterInterface
19
{
20
    protected $options;
21
    protected $arguments = array();
22

    
23
    public function __construct(array $options = array())
24
    {
25
        $this->options = array_merge(array(
26
            'needs_environment' => false,
27
            'needs_context'     => false,
28
            'pre_escape'        => null,
29
            'preserves_safety'  => null,
30
        ), $options);
31
    }
32

    
33
    public function setArguments($arguments)
34
    {
35
        $this->arguments = $arguments;
36
    }
37

    
38
    public function getArguments()
39
    {
40
        return $this->arguments;
41
    }
42

    
43
    public function needsEnvironment()
44
    {
45
        return $this->options['needs_environment'];
46
    }
47

    
48
    public function needsContext()
49
    {
50
        return $this->options['needs_context'];
51
    }
52

    
53
    public function getSafe(Twig_Node $filterArgs)
54
    {
55
        if (isset($this->options['is_safe'])) {
56
            return $this->options['is_safe'];
57
        }
58

    
59
        if (isset($this->options['is_safe_callback'])) {
60
            return call_user_func($this->options['is_safe_callback'], $filterArgs);
61
        }
62

    
63
        return null;
64
    }
65

    
66
    public function getPreservesSafety()
67
    {
68
        return $this->options['preserves_safety'];
69
    }
70

    
71
    public function getPreEscape()
72
    {
73
        return $this->options['pre_escape'];
74
    }
75
}
(11-11/34)