public function expose($name, $function = null, $as = 'function')
    {
        $this->assertViewVariableName($name);
        
        if ($as === 'function') {
            $function = new \Twig_SimpleFunction($name, $function ?: $name);
            $this->getTwig()->addFunction($function);
        } elseif ($as === 'filter') {
            $filter = new \Twig_SimpleFilter($name, $function ?: $name);
            $this->getTwig()->addFilter($filter);
        } else {
            $not = is_string($as) ? "'$as'" : gettype($as);
            throw new \InvalidArgumentException("You can create either a 'function' or 'filter', not a $not");
        }

        return $this;
    }
public function expose($name, $function = null, $as = 'function')
    {
        $this->assertViewVariableName($name);
        
        if ($as === 'function') {
            $function = new \Twig_SimpleFunction($name, $function ?: $name);
            $this->getTwig()->addFunction($function);
        } elseif ($as === 'filter') {
            $filter = new \Twig_SimpleFilter($name, $function ?: $name);
            $this->getTwig()->addFilter($filter);
        } else {
            $not = is_string($as) ? "'$as'" : gettype($as);
            throw new \InvalidArgumentException("You can create either a 'function' or 'filter', not a $not");
        }

        return $this;
    }
public function expose ( $ name , $ function = null , $ as = 'function' ) { $ this -> assertViewVariableName ( $ name ) ; if ( $ as === 'function' ) { $ function = new \ Twig_SimpleFunction ( $ name , $ function ? : $ name ) ; $ this -> getTwig ( ) -> addFunction ( $ function ) ; } elseif ( $ as === 'filter' ) { $ filter = new \ Twig_SimpleFilter ( $ name , $ function ? : $ name ) ; $ this -> getTwig ( ) -> addFilter ( $ filter ) ; } else { $ not = is_string ( $ as ) ? "'$as'" : gettype ( $ as ) ; throw new \ InvalidArgumentException ( "You can create either a 'function' or 'filter', not a $not" ) ; } return $ this ; }
Expose a function to the view.

@param string        $name      Function name in template
@param callable|null $function
@param string        $as        'function' or 'filter'
@return $this
Expose a function to the view .