/** * @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; }
/** * Checks if a logger exists * * @param string|null $name * @return bool */ public function hasLogger($name = null) { require_once $this->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Plugin/Logger.php'; return IfwPsn_Wp_Plugin_Logger::hasInstance($this, $name); }
/** * 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; }