Dotclear

source: inc/libs/twig/Filter.php @ 0:54703be25dd6

Revision 0:54703be25dd6, 1.3 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

Line 
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.potencier@symfony-project.com>
17 */
18abstract class Twig_Filter implements Twig_FilterInterface
19{
20    protected $options;
21
22    public function __construct(array $options = array())
23    {
24        $this->options = array_merge(array(
25            'needs_environment' => false,
26            'needs_context'     => false,
27            'pre_escape'        => null,
28        ), $options);
29    }
30
31    public function needsEnvironment()
32    {
33        return $this->options['needs_environment'];
34    }
35
36    public function needsContext()
37    {
38        return $this->options['needs_context'];
39    }
40
41    public function getSafe(Twig_Node $filterArgs)
42    {
43        if (isset($this->options['is_safe'])) {
44            return $this->options['is_safe'];
45        }
46
47        if (isset($this->options['is_safe_callback'])) {
48            return call_user_func($this->options['is_safe_callback'], $filterArgs);
49        }
50
51        return array();
52    }
53
54    public function getPreEscape()
55    {
56        return $this->options['pre_escape'];
57    }
58}
Note: See TracBrowser for help on using the repository browser.

Sites map