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
12namespace Twig\Extension;
13
14use Twig\NodeVisitor\NodeVisitorInterface;
15use Twig\TokenParser\TokenParserInterface;
16
17/**
18 * Internal class.
19 *
20 * This class is used by \Twig\Environment as a staging area and must not be used directly.
21 *
22 * @author Fabien Potencier <fabien@symfony.com>
23 *
24 * @internal
25 */
26class StagingExtension extends AbstractExtension
27{
28    protected $functions = [];
29    protected $filters = [];
30    protected $visitors = [];
31    protected $tokenParsers = [];
32    protected $globals = [];
33    protected $tests = [];
34
35    public function addFunction($name, $function)
36    {
37        if (isset($this->functions[$name])) {
38            @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
39        }
40
41        $this->functions[$name] = $function;
42    }
43
44    public function getFunctions()
45    {
46        return $this->functions;
47    }
48
49    public function addFilter($name, $filter)
50    {
51        if (isset($this->filters[$name])) {
52            @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
53        }
54
55        $this->filters[$name] = $filter;
56    }
57
58    public function getFilters()
59    {
60        return $this->filters;
61    }
62
63    public function addNodeVisitor(NodeVisitorInterface $visitor)
64    {
65        $this->visitors[] = $visitor;
66    }
67
68    public function getNodeVisitors()
69    {
70        return $this->visitors;
71    }
72
73    public function addTokenParser(TokenParserInterface $parser)
74    {
75        if (isset($this->tokenParsers[$parser->getTag()])) {
76            @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
77        }
78
79        $this->tokenParsers[$parser->getTag()] = $parser;
80    }
81
82    public function getTokenParsers()
83    {
84        return $this->tokenParsers;
85    }
86
87    public function addGlobal($name, $value)
88    {
89        $this->globals[$name] = $value;
90    }
91
92    public function getGlobals()
93    {
94        return $this->globals;
95    }
96
97    public function addTest($name, $test)
98    {
99        if (isset($this->tests[$name])) {
100            @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
101        }
102
103        $this->tests[$name] = $test;
104    }
105
106    public function getTests()
107    {
108        return $this->tests;
109    }
110
111    public function getName()
112    {
113        return 'staging';
114    }
115}
116
117class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging');
118