From 8030c1292392562af9c9a8ce660635aeb965cc8b Mon Sep 17 00:00:00 2001 From: bzick Date: Wed, 24 Jul 2013 16:16:20 +0400 Subject: [PATCH] =?UTF-8?q?Add=20{unset=20=E2=80=A6}=20(#29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Fenom.php | 4 ++++ src/Fenom/Compiler.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Fenom.php b/src/Fenom.php index 4334b33..c0eb7bf 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -228,6 +228,10 @@ class Fenom { 'type' => self::BLOCK_COMPILER, 'open' => 'Fenom\Compiler::autoescapeOpen', 'close' => 'Fenom\Compiler::autoescapeClose' + ), + 'unset' => array( + 'type' => self::INLINE_COMPILER, + 'parser' => 'Fenom\Compiler::tagUnset' ) ); diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index d125856..30e390a 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -914,4 +914,23 @@ class Compiler { public static function autoescapeClose(Tokenizer $tokens, Scope $scope) { $scope->tpl->escape = $scope["escape"]; } + + /** + * Unset present variables + * + * @param Tokenizer $tokens + * @param Template $tpl + * @return string + * @throws InvalidUsageException + */ + public static function tagUnset(Tokenizer $tokens, Template $tpl) { + $vars = array(); + while($tokens->valid()) { + $vars[] = $tpl->parseVar($tokens); + } + if(!$vars) { + throw new InvalidUsageException("Unset must accept variable(s)"); + } + return 'unset('.implode(', ', $vars).')'; + } }