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_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED);
15
16/**
17 * Represents a template function.
18 *
19 * Use \Twig\TwigFunction 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_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface
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            'callable' => null,
36        ], $options);
37    }
38
39    public function setArguments($arguments)
40    {
41        $this->arguments = $arguments;
42    }
43
44    public function getArguments()
45    {
46        return $this->arguments;
47    }
48
49    public function needsEnvironment()
50    {
51        return $this->options['needs_environment'];
52    }
53
54    public function needsContext()
55    {
56        return $this->options['needs_context'];
57    }
58
59    public function getSafe(Node $functionArgs)
60    {
61        if (isset($this->options['is_safe'])) {
62            return $this->options['is_safe'];
63        }
64
65        if (isset($this->options['is_safe_callback'])) {
66            return \call_user_func($this->options['is_safe_callback'], $functionArgs);
67        }
68
69        return [];
70    }
71
72    public function getCallable()
73    {
74        return $this->options['callable'];
75    }
76}
77