yii\twig\ViewRenderer::_addCustom PHP Method

_addCustom() private method

Adds custom function or filter
private _addCustom ( string $classType, array $elements )
$classType string 'Function' or 'Filter'
$elements array Parameters of elements to add
    private function _addCustom($classType, $elements)
    {
        $classFunction = 'Twig_Simple' . $classType;
        foreach ($elements as $name => $func) {
            $twigElement = null;
            switch ($func) {
                // Callable (including just a name of function).
                case is_callable($func):
                    $twigElement = new $classFunction($name, $func);
                    break;
                    // Callable (including just a name of function) + options array.
                // Callable (including just a name of function) + options array.
                case is_array($func) && is_callable($func[0]):
                    $twigElement = new $classFunction($name, $func[0], !empty($func[1]) && is_array($func[1]) ? $func[1] : []);
                    break;
                case $func instanceof \Twig_SimpleFunction || $func instanceof \Twig_SimpleFilter:
                    $twigElement = $func;
            }
            if ($twigElement !== null) {
                $this->twig->{'add' . $classType}($twigElement);
            } else {
                throw new \Exception("Incorrect options for \"{$classType}\" {$name}.");
            }
        }
    }