Exemplo n.º 1
0
 /**
  * Output value as is, without escaping
  *
  * @param Tokenizer $tokens
  * @param Template $tpl
  * @throws InvalidUsageException
  * @return string
  */
 public static function tagRaw(Tokenizer $tokens, Template $tpl)
 {
     $escape = (bool) $tpl->escape;
     $tpl->escape = false;
     if ($tokens->is(':')) {
         $func = $tokens->getNext(Tokenizer::MACRO_STRING);
         $tag = $tpl->getStorage()->getTag($func, $tpl);
         if ($tag["type"] == \Fenom::INLINE_FUNCTION) {
             $code = $tpl->parseAct($tokens);
             //            } elseif ($tag["type"] == \Fenom::BLOCK_FUNCTION) {
             //                $code = $tpl->parseAct($tokens);
             //                $tpl->getLastScope()->escape = false;
             //                return $code;
         } else {
             throw new InvalidUsageException("Raw mode allow for expressions or functions");
         }
     } else {
         $code = $tpl->out($tpl->parseExpr($tokens));
     }
     $tpl->escape = $escape;
     return $code;
 }
Exemplo n.º 2
0
 /**
  * Parse modifiers
  * |modifier:1:2.3:'string':false:$var:(4+5*$var3)|modifier2:"str {$var+3} ing":$arr.item
  *
  * @param Tokenizer $tokens
  * @param                    $value
  * @throws \LogicException
  * @throws \Exception
  * @return string
  */
 public function parseModifier(Tokenizer $tokens, $value)
 {
     while ($tokens->is("|")) {
         $modifier = $tokens->getNext(Tokenizer::MACRO_STRING);
         if ($tokens->isNext(T_DOUBLE_COLON, T_NS_SEPARATOR)) {
             $mods = $this->parseStatic($tokens);
         } else {
             $mods = $this->_fenom->getModifier($modifier, $this);
             if (!$mods) {
                 throw new \Exception("Modifier " . $tokens->current() . " not found");
             }
             $tokens->next();
         }
         $args = array();
         while ($tokens->is(":")) {
             if (($args[] = $this->parseTerm($tokens->next(), $is_var, 0)) === false) {
                 throw new UnexpectedTokenException($tokens);
             }
         }
         if (!is_string($mods)) {
             // dynamic modifier
             $mods = 'call_user_func($tpl->getStorage()->getModifier("' . $modifier . '"), ';
         } else {
             $mods .= "(";
         }
         if ($args) {
             $value = $mods . $value . ', ' . implode(", ", $args) . ')';
         } else {
             $value = $mods . $value . ')';
         }
     }
     return $value;
 }