shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

SimpleFunction.php (2452B)


      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  * @author Fabien Potencier <fabien@symfony.com>
     16  */
     17 class Twig_SimpleFunction
     18 {
     19     protected $name;
     20     protected $callable;
     21     protected $options;
     22     protected $arguments = array();
     23 
     24     public function __construct($name, $callable, array $options = array())
     25     {
     26         $this->name = $name;
     27         $this->callable = $callable;
     28         $this->options = array_merge(array(
     29             'needs_environment' => false,
     30             'needs_context' => false,
     31             'is_variadic' => false,
     32             'is_safe' => null,
     33             'is_safe_callback' => null,
     34             'node_class' => 'Twig_Node_Expression_Function',
     35             'deprecated' => false,
     36             'alternative' => null,
     37         ), $options);
     38     }
     39 
     40     public function getName()
     41     {
     42         return $this->name;
     43     }
     44 
     45     public function getCallable()
     46     {
     47         return $this->callable;
     48     }
     49 
     50     public function getNodeClass()
     51     {
     52         return $this->options['node_class'];
     53     }
     54 
     55     public function setArguments($arguments)
     56     {
     57         $this->arguments = $arguments;
     58     }
     59 
     60     public function getArguments()
     61     {
     62         return $this->arguments;
     63     }
     64 
     65     public function needsEnvironment()
     66     {
     67         return $this->options['needs_environment'];
     68     }
     69 
     70     public function needsContext()
     71     {
     72         return $this->options['needs_context'];
     73     }
     74 
     75     public function getSafe(Twig_Node $functionArgs)
     76     {
     77         if (null !== $this->options['is_safe']) {
     78             return $this->options['is_safe'];
     79         }
     80 
     81         if (null !== $this->options['is_safe_callback']) {
     82             return call_user_func($this->options['is_safe_callback'], $functionArgs);
     83         }
     84 
     85         return array();
     86     }
     87 
     88     public function isVariadic()
     89     {
     90         return $this->options['is_variadic'];
     91     }
     92 
     93     public function isDeprecated()
     94     {
     95         return (bool) $this->options['deprecated'];
     96     }
     97 
     98     public function getDeprecatedVersion()
     99     {
    100         return $this->options['deprecated'];
    101     }
    102 
    103     public function getAlternative()
    104     {
    105         return $this->options['alternative'];
    106     }
    107 }