1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 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
12use Twig\Node\Node;
13
14@trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED);
15
16/**
17 * Represents a template filter.
18 *
19 * Use \Twig\TwigFilter instead.
20 *
21 * @author Fabien Potencier <fabien@symfony.com>
22 *
23 * @deprecated since 1.12 (to be removed in 2.0)
24 */
25abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface
26{
27    protected $options;
28    protected $arguments = [];
29
30    public function __construct(array $options = [])
31    {
32        $this->options = array_merge([
33            'needs_environment' => false,
34            'needs_context' => false,
35            'pre_escape' => null,
36            'preserves_safety' => null,
37            'callable' => null,
38        ], $options);
39    }
40
41    public function setArguments($arguments)
42    {
43        $this->arguments = $arguments;
44    }
45
46    public function getArguments()
47    {
48        return $this->arguments;
49    }
50
51    public function needsEnvironment()
52    {
53        return $this->options['needs_environment'];
54    }
55
56    public function needsContext()
57    {
58        return $this->options['needs_context'];
59    }
60
61    public function getSafe(Node $filterArgs)
62    {
63        if (isset($this->options['is_safe'])) {
64            return $this->options['is_safe'];
65        }
66
67        if (isset($this->options['is_safe_callback'])) {
68            return \call_user_func($this->options['is_safe_callback'], $filterArgs);
69        }
70    }
71
72    public function getPreservesSafety()
73    {
74        return $this->options['preserves_safety'];
75    }
76
77    public function getPreEscape()
78    {
79        return $this->options['pre_escape'];
80    }
81
82    public function getCallable()
83    {
84        return $this->options['callable'];
85    }
86}
87