| 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 | * Use Twig_SimpleFilter instead. |
|---|
| 16 | * |
|---|
| 17 | * @package twig |
|---|
| 18 | * @author Fabien Potencier <fabien@symfony.com> |
|---|
| 19 | * @deprecated since 1.12 (to be removed in 2.0) |
|---|
| 20 | */ |
|---|
| 21 | abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface |
|---|
| 22 | { |
|---|
| 23 | protected $options; |
|---|
| 24 | protected $arguments = array(); |
|---|
| 25 | |
|---|
| 26 | public function __construct(array $options = array()) |
|---|
| 27 | { |
|---|
| 28 | $this->options = array_merge(array( |
|---|
| 29 | 'needs_environment' => false, |
|---|
| 30 | 'needs_context' => false, |
|---|
| 31 | 'pre_escape' => null, |
|---|
| 32 | 'preserves_safety' => null, |
|---|
| 33 | 'callable' => null, |
|---|
| 34 | ), $options); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public function setArguments($arguments) |
|---|
| 38 | { |
|---|
| 39 | $this->arguments = $arguments; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | public function getArguments() |
|---|
| 43 | { |
|---|
| 44 | return $this->arguments; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public function needsEnvironment() |
|---|
| 48 | { |
|---|
| 49 | return $this->options['needs_environment']; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | public function needsContext() |
|---|
| 53 | { |
|---|
| 54 | return $this->options['needs_context']; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public function getSafe(Twig_Node $filterArgs) |
|---|
| 58 | { |
|---|
| 59 | if (isset($this->options['is_safe'])) { |
|---|
| 60 | return $this->options['is_safe']; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | if (isset($this->options['is_safe_callback'])) { |
|---|
| 64 | return call_user_func($this->options['is_safe_callback'], $filterArgs); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | return null; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | public function getPreservesSafety() |
|---|
| 71 | { |
|---|
| 72 | return $this->options['preserves_safety']; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | public function getPreEscape() |
|---|
| 76 | { |
|---|
| 77 | return $this->options['pre_escape']; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | public function getCallable() |
|---|
| 81 | { |
|---|
| 82 | return $this->options['callable']; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|