Advertisement
Guest User

TwigPHPExtension.php

a guest
Mar 29th, 2014
1,708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. class TwigPHPExtension extends \Twig_Extension {
  3.  
  4.     public function getName()
  5.     {
  6.         return 'php_twig_extension';
  7.     }
  8.  
  9.     public function getFunctions()
  10.     {
  11.         return array(
  12.             new \Twig_SimpleFunction('php_*', array($this,'phpFunctions'),array('is_safe' => array('html')))
  13.         );
  14.     }
  15.  
  16.     public function phpFunctions()
  17.     {
  18.         $arg_list = func_get_args();
  19.         $function = array_shift($arg_list);
  20.  
  21.         if(is_callable($function)){
  22.             return call_user_func_array($function, $arg_list);
  23.         }
  24.  
  25.         $errMsg = 'Called to an undefined function : <b>php_' . $function . "</b> ";
  26.  
  27.         trigger_error($errMsg, E_USER_NOTICE);
  28.  
  29.         return NULL;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement