/** * Add a Twig Function. * * @param string $name * @param string|array $callback * @param array $options */ public function addTwigFunction($name, $callback, $options = array()) { if (is_string($callback)) { $callback = array($this, $callback); } $this->initializeTwig(); $this->twigExtension->addTwigFunction(new \Twig_SimpleFunction($name, $callback, $options)); }
/** * Add a Twig Function. * * @param string $name * @param string $callback * @param array $options */ public function addTwigFunction($name, $callback, $options = []) { // If we pass a callback as a simple string, we need to turn it into an array. if (is_string($callback) && method_exists($this, $callback)) { $callback = [$this, $callback]; } $this->initializeTwig(); $this->twigExtension->addTwigFunction(new \Twig_SimpleFunction($name, $callback, $options)); }
public function testSetup() { $twig = new TwigProxy('mytest'); $func = $this->getMock('\\Twig_SimpleFunction', null, array('test', function () { })); $filter = $this->getMock('\\Twig_SimpleFilter', null, array('testfilter', function () { })); $twig->addTwigFunction($func); $twig->addTwigFilter($filter); $this->assertEquals(1, count($twig->getFunctions())); $this->assertEquals(1, count($twig->getFilters())); $this->assertEquals('mytest', $twig->getName()); }
/** * Add a Twig Function. * * @param string $name * @param string $callback * @param array $options */ public function addTwigFunction($name, $callback, $options = []) { $this->initializeTwig(); $this->twigExtension->addTwigFunction(new \Twig_SimpleFunction($name, [$this, $callback], $options)); }