コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
ファイル: BaseExtension.php プロジェクト: richardudovich/bolt
 /**
  * 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));
 }
コード例 #3
0
ファイル: TwigProxyTest.php プロジェクト: aaleksu/bolt_cm
 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());
 }
コード例 #4
0
ファイル: BaseExtension.php プロジェクト: halechan/bolt
 /**
  * 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));
 }