/** * @param Tokenizer $tokens * @param Scope $scope */ public static function macroClose(Tokenizer $tokens, Scope $scope) { if ($scope["recursive"]) { $scope["macro"]["recursive"] = true; } $scope["macro"]["body"] = $scope->cutContent(); $scope->tpl->macros[$scope["name"]] = $scope["macro"]; }
/** * Parse action {action ...} or {action(...) ...} * * @static * @param Tokenizer $tokens * @throws \LogicException * @throws TokenizeException * @return string */ public function parseAct(Tokenizer $tokens) { if ($tokens->is(Tokenizer::MACRO_STRING)) { $action = $tokens->getAndNext(); } else { return $this->out($this->parseExpr($tokens)); // may be math and/or boolean expression } if ($tokens->is("(", T_NAMESPACE, T_DOUBLE_COLON) && !$tokens->isWhiteSpaced()) { // just invoke function or static method $tokens->back(); return $this->out($this->parseExpr($tokens)); } if ($tokens->is('.')) { $name = $tokens->skip()->get(Tokenizer::MACRO_STRING); if ($action !== "macro") { $name = $action . "." . $name; } return $this->parseMacroCall($tokens, $name); } if ($tag = $this->_fenom->getTag($action, $this)) { // call some function switch ($tag["type"]) { case Fenom::BLOCK_COMPILER: $scope = new Scope($action, $this, $this->_line, $tag, count($this->_stack), $this->_body); $code = $scope->open($tokens); if (!$scope->is_closed) { array_push($this->_stack, $scope); } return $code; case Fenom::INLINE_COMPILER: return call_user_func($tag["parser"], $tokens, $this); case Fenom::INLINE_FUNCTION: return $this->out(call_user_func($tag["parser"], $tag["function"], $tokens, $this)); case Fenom::BLOCK_FUNCTION: $scope = new Scope($action, $this, $this->_line, $tag, count($this->_stack), $this->_body); $scope->setFuncName($tag["function"]); array_push($this->_stack, $scope); $scope->escape = $this->escape; $this->escape = false; return $scope->open($tokens); default: throw new \LogicException("Unknown function type"); } } for ($j = $i = count($this->_stack) - 1; $i >= 0; $i--) { // call function's internal tag if ($this->_stack[$i]->hasTag($action, $j - $i)) { return $this->_stack[$i]->tag($action, $tokens); } } if ($tags = $this->_fenom->getTagOwners($action)) { // unknown template tag throw new TokenizeException("Unexpected tag '{$action}' (this tag can be used with '" . implode("', '", $tags) . "')"); } else { throw new TokenizeException("Unexpected tag {$action}"); } }