id = ++self::$count; $this->line = $line; $this->name = $name; $this->tpl = $tpl; $this->_action = $action; $this->level = $level; } /** * * @param string $function */ public function setFuncName($function) { $this["function"] = $function; $this->is_compiler = false; } /** * Open callback * * @param Tokenizer $tokenizer * @return mixed */ public function open($tokenizer) { return call_user_func($this->_action["open"], $tokenizer, $this)." /*#{$this->id}#*/"; } /** * Check, has the block this tag * * @param string $tag * @param int $level * @return bool */ public function hasTag($tag, $level) { if(isset($this->_action["tags"][$tag])) { if($level) { return isset($this->_action["float_tags"][$tag]); } else { return true; } } return false; } /** * Call tag callback * * @param string $tag * @param Tokenizer $tokenizer * @return string */ public function tag($tag, $tokenizer) { return call_user_func($this->_action["tags"][$tag], $tokenizer, $this); } /** * Close callback * * @param Tokenizer $tokenizer * @return string */ public function close($tokenizer) { return call_user_func($this->_action["close"], $tokenizer, $this); } /** * Return content of block * * @throws \LogicException * @return string */ public function getContent() { if($pos = strpos($this->tpl->_body, "/*#{$this->id}#*/")) { $begin = strpos($this->tpl->_body, "?>", $pos); return substr($this->tpl->_body, $begin + 2); } else { throw new \LogicException("Trying get content of non-block scope"); } } /** * @return string * @throws \LogicException */ public function cutContent() { if($pos = strpos($this->tpl->_body, "/*#{$this->id}#*/")) { $begin = strpos($this->tpl->_body, "?>", $pos); $content = substr($this->tpl->_body, $begin + 2); $this->tpl->_body = substr($this->tpl->_body, 0, $begin + 1); return $content; } else { throw new \LogicException("Trying cut content of non-block scope"); } } }