示例#1
0
文件: Parser.php 项目: jasmun/Noco100
 /**
  * @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;
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
文件: Tpl.php 项目: jasmun/Noco100
 /**
  * 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;
 }