Dotclear

source: inc/libs/Twig/SimpleFunction.php @ 1149:1657e862089c

Revision 1149:1657e862089c, 1.9 KB checked in by dsls, 13 years ago (diff)

Fixed unix case-sensitive twig directory

Line 
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010-2012 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 function.
14 *
15 * @package    twig
16 * @author     Fabien Potencier <fabien@symfony.com>
17 */
18class Twig_SimpleFunction
19{
20    protected $name;
21    protected $callable;
22    protected $options;
23    protected $arguments = array();
24
25    public function __construct($name, $callable, array $options = array())
26    {
27        $this->name = $name;
28        $this->callable = $callable;
29        $this->options = array_merge(array(
30            'needs_environment' => false,
31            'needs_context'     => false,
32            'is_safe'           => null,
33            'is_safe_callback'  => null,
34            'node_class'        => 'Twig_Node_Expression_Function',
35        ), $options);
36    }
37
38    public function getName()
39    {
40        return $this->name;
41    }
42
43    public function getCallable()
44    {
45        return $this->callable;
46    }
47
48    public function getNodeClass()
49    {
50        return $this->options['node_class'];
51    }
52
53    public function setArguments($arguments)
54    {
55        $this->arguments = $arguments;
56    }
57
58    public function getArguments()
59    {
60        return $this->arguments;
61    }
62
63    public function needsEnvironment()
64    {
65        return $this->options['needs_environment'];
66    }
67
68    public function needsContext()
69    {
70        return $this->options['needs_context'];
71    }
72
73    public function getSafe(Twig_Node $functionArgs)
74    {
75        if (null !== $this->options['is_safe']) {
76            return $this->options['is_safe'];
77        }
78
79        if (null !== $this->options['is_safe_callback']) {
80            return call_user_func($this->options['is_safe_callback'], $functionArgs);
81        }
82
83        return array();
84    }
85}
Note: See TracBrowser for help on using the repository browser.

Sites map