/** * Add a Twig Filter. * * @param string $name * @param string|array $callback * @param array $options */ public function addTwigFilter($name, $callback, $options = array()) { if (is_string($callback)) { $callback = array($this, $callback); } $this->initializeTwig(); $this->twigExtension->addTwigFilter(new \Twig_SimpleFilter($name, $callback, $options)); }
/** * Add a Twig Filter. * * @param string $name * @param string $callback * @param array $options */ public function addTwigFilter($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->addTwigFilter(new \Twig_SimpleFilter($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 Filter. * * @param string $name * @param string $callback * @param array $options */ public function addTwigFilter($name, $callback, $options = []) { $this->initializeTwig(); $this->twigExtension->addTwigFilter(new \Twig_SimpleFilter($name, [$this, $callback], $options)); }