diff --git a/src/Fenom.php b/src/Fenom.php index e6e130c..bdb6b9e 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -574,7 +574,8 @@ class Fenom * @param string $name test name * @param string $code test PHP code. Code may contains placeholder %s, which will be replaced by test-value. For example: is_callable(%s) */ - public function addTest($name, $code) { + public function addTest($name, $code) + { $this->_tests[$name] = $code; } @@ -583,7 +584,8 @@ class Fenom * @param string $name * @return string|bool */ - public function getTest($name) { + public function getTest($name) + { return isset($this->_tests[$name]) ? $this->_tests[$name] : false; } diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index 3577961..dd75ab7 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -628,7 +628,7 @@ class Compiler */ public static function stdFuncParser(Tokenizer $tokens, Tag $tag) { - return $tag->escape($tag->callback."(" . self::toArray($tag->tpl->parseParams($tokens)) . ', $tpl)'); + return $tag->escape($tag->callback . "(" . self::toArray($tag->tpl->parseParams($tokens)) . ', $tpl)'); } /** @@ -658,7 +658,7 @@ class Compiler $args[] = var_export($param->getDefaultValue(), true); } } - return $tag->escape($tag->callback."(" . implode(", ", $args) . ')'); + return $tag->escape($tag->callback . "(" . implode(", ", $args) . ')'); } /** @@ -891,7 +891,7 @@ class Compiler } while ($tokens->is(Tokenizer::MACRO_STRING, T_VARIABLE)) { $param = $tokens->current(); - if($tokens->is(T_VARIABLE)) { + if ($tokens->is(T_VARIABLE)) { $param = ltrim($param, '$'); } $tokens->next(); @@ -939,7 +939,7 @@ class Compiler */ public static function tagRaw(Tokenizer $tokens, Tag $tag) { - return 'echo '.$tag->tpl->parseExpr($tokens); + return 'echo ' . $tag->tpl->parseExpr($tokens); } /** diff --git a/src/Fenom/Render.php b/src/Fenom/Render.php index 6f9afa3..f72d48a 100644 --- a/src/Fenom/Render.php +++ b/src/Fenom/Render.php @@ -202,7 +202,7 @@ class Render extends \ArrayObject public function getMacro($name) { if (empty($this->_macros[$name])) { - throw new \RuntimeException('macro '.$name.' not found'); + throw new \RuntimeException('macro ' . $name . ' not found'); } return $this->_macros[$name]; } diff --git a/src/Fenom/Scope.php b/src/Fenom/Scope.php deleted file mode 100644 index 8f0f764..0000000 --- a/src/Fenom/Scope.php +++ /dev/null @@ -1,153 +0,0 @@ - - */ -class Scope extends \ArrayObject -{ - - public $line = 0; - public $name; - public $level = 0; - /** - * @var Template - */ - public $tpl; - public $is_compiler = true; - public $is_closed = false; - public $options; - private $_action; - private $_body; - private $_offset; - - /** - * Creating cope - * - * @param string $name - * @param Template $tpl - * @param int $line - * @param array $action - * @param int $level - * @param $body - */ - public function __construct($name, $tpl, $line, $action, $level, &$body) - { - $this->line = $line; - $this->name = $name; - $this->tpl = $tpl; - $this->_action = $action; - $this->level = $level; - $this->_body = & $body; - $this->_offset = strlen($body); - } - - /** - * - * @param string $function - */ - public function setFuncName($function) - { - $this["function"] = $function; - $this->is_compiler = false; - $this->escape = $this->tpl->escape; - } - - /** - * Open callback - * - * @param Tokenizer $tokenizer - * @return mixed - */ - public function open($tokenizer) - { - return call_user_func($this->_action["open"], $tokenizer, $this); - } - - /** - * 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() - { - return substr($this->_body, $this->_offset); - } - - /** - * Cut scope content - * - * @return string - * @throws \LogicException - */ - public function cutContent() - { - $content = substr($this->_body, $this->_offset + 1); - $this->_body = substr($this->_body, 0, $this->_offset); - return $content; - } - - /** - * Replace scope content - * - * @param $new_content - */ - public function replaceContent($new_content) - { - $this->cutContent(); - $this->_body .= $new_content; - } -} \ No newline at end of file diff --git a/src/Fenom/Tag.php b/src/Fenom/Tag.php index e7426bc..15358ab 100644 --- a/src/Fenom/Tag.php +++ b/src/Fenom/Tag.php @@ -10,10 +10,11 @@ namespace Fenom; -class Tag extends \ArrayObject { +class Tag extends \ArrayObject +{ const COMPILER = 1; - const FUNC = 2; - const BLOCK = 4; + const FUNC = 2; + const BLOCK = 4; /** * @var Template @@ -34,36 +35,53 @@ class Tag extends \ArrayObject { private $_tags = array(); private $_floats = array(); + /** + * Create tag entity + * @param string $name the tag name + * @param Template $tpl current template + * @param string $info tag's information + * @param string $body template's code + */ public function __construct($name, Template $tpl, $info, &$body) { $this->tpl = $tpl; $this->name = $name; $this->line = $tpl->getLine(); $this->level = $tpl->getStackSize(); - $this->_body = &$body; + $this->_body = & $body; $this->_offset = strlen($body); $this->_type = $info["type"]; - if($this->_type & self::BLOCK) { + if ($this->_type & self::BLOCK) { $this->_open = $info["open"]; $this->_close = $info["close"]; $this->_tags = isset($info["tags"]) ? $info["tags"] : array(); $this->_floats = isset($info["float_tags"]) ? $info["float_tags"] : array(); $this->_closed = false; - } else { + } else { $this->_open = $info["parser"]; } - if($this->_type & self::FUNC) { + if ($this->_type & self::FUNC) { $this->callback = $info["function"]; } } - public function setOption($option) { + /** + * Set tag option + * @param string $option + */ + public function setOption($option) + { } - public function isClosed() { + /** + * Check, if the tag closed + * @return bool + */ + public function isClosed() + { return $this->_closed; } @@ -124,17 +142,21 @@ class Tag extends \ArrayObject { */ public function end($tokenizer) { - if($this->_closed) { + if ($this->_closed) { throw new \LogicException("Tag {$this->name} already closed"); } - if($this->_close) { + if ($this->_close) { return call_user_func($this->_close, $tokenizer, $this); } else { throw new \LogicException("Сan not use a inline tag {$this->name} as a block"); } } - public function close() { + /** + * Forcefully close the tag + */ + public function close() + { $this->_closed = true; } @@ -173,28 +195,33 @@ class Tag extends \ArrayObject { $this->_body .= $new_content; } - public function escape($code) { - + public function escape($code) + { return $this->tpl->out($code); } - public function optLtrim() { + public function optLtrim() + { } - public function optRtrim() { + public function optRtrim() + { } - public function optTrim() { + public function optTrim() + { } - public function optRaw() { + public function optRaw() + { } - public function optEscape() { + public function optEscape() + { } } \ No newline at end of file diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index d9bea6c..a020e98 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -588,10 +588,10 @@ class Template extends Render } if ($info = $this->_fenom->getTag($action, $this)) { $tag = new Tag($action, $this, $info, $this->_body); - if($tokens->is(':')) { // parse tag options + if ($tokens->is(':')) { // parse tag options do { $tag->setOption($tokens->next()->need(T_STRING)->getAndNext()); - } while($tokens->is(':')); + } while ($tokens->is(':')); } $code = $tag->start($tokens); if (!$tag->isClosed()) { @@ -616,7 +616,8 @@ class Template extends Render * Get current template line * @return int */ - public function getLine() { + public function getLine() + { return $this->_line; } @@ -1307,10 +1308,10 @@ class Template extends Render } } if ($recursive) { - if($recursive instanceof Tag) { + if ($recursive instanceof Tag) { $recursive['recursive'] = true; } - return '$tpl->getMacro("' . $name . '")->__invoke('.Compiler::toArray($args).', $tpl);'; + return '$tpl->getMacro("' . $name . '")->__invoke(' . Compiler::toArray($args) . ', $tpl);'; } else { $vars = $this->tmpVar(); return $vars . ' = $var; $var = ' . Compiler::toArray($args) . ';' . PHP_EOL . '?>' .