Ejemplo n.º 1
0
 /**
  * @param $string
  * @param array $context
  * @param null|callable $exceptionHandler
  * @return string
  */
 public function parse($string, $context = array(), $exceptionHandler = null)
 {
     if (!empty($string)) {
         try {
             if ($this->_env->getLoader() instanceof IfwPsn_Vendor_Twig_Loader_String) {
                 $string = $this->_sanitzeString($string);
             }
             $string = $this->_env->render($string, $context);
         } catch (Exception $e) {
             // invalid filter handling
             if (is_callable($exceptionHandler)) {
                 call_user_func_array($exceptionHandler, array($e));
             } else {
                 if ($this->_logger instanceof IfwPsn_Wp_Plugin_Logger) {
                     $this->_logger->err($e->getMessage());
                 }
             }
         }
     }
     return $string;
 }
Ejemplo n.º 2
0
 /**
  * Applies twig filters to string
  *
  * @param string $string
  * @param null|IfwPsn_Wp_Plugin_Logger $logger
  * @internal param string $filters
  * @return string
  */
 public static function renderString($string, $logger = null)
 {
     if (!empty($string)) {
         try {
             $tpl = self::getStringLoaderInstance();
             $string = strtr($string, array('{{ ' => '{{', ' }}' => '}}'));
             $string = $tpl->render($string);
         } catch (Exception $e) {
             // invalid filter handling
             if ($logger instanceof IfwPsn_Wp_Plugin_Logger) {
                 $logger->err($e->getMessage());
             }
         }
     }
     return $string;
 }