daily pastebin goal
87%
SHARE
TWEET

TwigPHPExtension.php

a guest Mar 29th, 2014 611 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top