2013-01-25 18:36:16 +04:00
|
|
|
<?php
|
|
|
|
namespace Aspect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope for blocks tags
|
|
|
|
*/
|
|
|
|
class Scope extends \ArrayObject {
|
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
public $id = 0;
|
2013-02-23 16:35:11 +04:00
|
|
|
public $line = 0;
|
|
|
|
public $name;
|
2013-02-20 18:12:44 +04:00
|
|
|
public $level = 0;
|
2013-02-23 16:35:11 +04:00
|
|
|
/**
|
|
|
|
* @var Template
|
|
|
|
*/
|
|
|
|
public $tpl;
|
|
|
|
public $is_compiler = true;
|
|
|
|
private $_action;
|
2013-02-20 18:12:44 +04:00
|
|
|
private static $count = 0;
|
2013-01-25 18:36:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param Template $tpl
|
|
|
|
* @param int $line
|
|
|
|
* @param array $action
|
2013-02-20 18:12:44 +04:00
|
|
|
* @param int $level
|
2013-01-25 18:36:16 +04:00
|
|
|
*/
|
2013-02-20 18:12:44 +04:00
|
|
|
public function __construct($name, $tpl, $line, $action, $level) {
|
|
|
|
$this->id = ++self::$count;
|
2013-02-23 16:35:11 +04:00
|
|
|
$this->line = $line;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->tpl = $tpl;
|
|
|
|
$this->_action = $action;
|
|
|
|
$this->level = $level;
|
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $function
|
|
|
|
*/
|
2013-01-25 18:36:16 +04:00
|
|
|
public function setFuncName($function) {
|
|
|
|
$this["function"] = $function;
|
|
|
|
$this->is_compiler = false;
|
|
|
|
}
|
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
/**
|
|
|
|
* Open callback
|
|
|
|
*
|
|
|
|
* @param Tokenizer $tokenizer
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2013-01-25 18:36:16 +04:00
|
|
|
public function open($tokenizer) {
|
2013-02-20 18:12:44 +04:00
|
|
|
return call_user_func($this->_action["open"], $tokenizer, $this)." /*#{$this->id}#*/";
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
/**
|
|
|
|
* Check, has the block this tag
|
|
|
|
*
|
|
|
|
* @param string $tag
|
|
|
|
* @param int $level
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasTag($tag, $level) {
|
2013-02-23 16:35:11 +04:00
|
|
|
if(isset($this->_action["tags"][$tag])) {
|
2013-01-25 18:36:16 +04:00
|
|
|
if($level) {
|
|
|
|
return isset($this->_action["float_tags"][$tag]);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-23 16:35:11 +04:00
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
/**
|
|
|
|
* Call tag callback
|
|
|
|
*
|
|
|
|
* @param string $tag
|
|
|
|
* @param Tokenizer $tokenizer
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function tag($tag, $tokenizer) {
|
2013-02-23 16:35:11 +04:00
|
|
|
return call_user_func($this->_action["tags"][$tag], $tokenizer, $this);
|
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-02-20 18:12:44 +04:00
|
|
|
/**
|
|
|
|
* Close callback
|
|
|
|
*
|
|
|
|
* @param Tokenizer $tokenizer
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-01-25 18:36:16 +04:00
|
|
|
public function close($tokenizer) {
|
|
|
|
return call_user_func($this->_action["close"], $tokenizer, $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-20 18:12:44 +04:00
|
|
|
* Return content of block
|
|
|
|
*
|
|
|
|
* @throws \LogicException
|
|
|
|
* @return string
|
2013-01-25 18:36:16 +04:00
|
|
|
*/
|
2013-02-20 18:12:44 +04:00
|
|
|
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");
|
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|
2013-02-26 23:56:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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");
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|