From 081e30e744ba06a275361a47b2b7854753d5d961 Mon Sep 17 00:00:00 2001 From: bzick Date: Tue, 6 Aug 2013 12:04:23 +0400 Subject: [PATCH] Fix #39 --- src/Fenom/Template.php | 32 ++---------------------------- tests/cases/Fenom/TemplateTest.php | 3 ++- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 0f22787..6902792 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -648,6 +648,8 @@ class Template extends Render break; } $cond = true; + } elseif ($tokens->is(Tokenizer::MACRO_BOOLEAN)) { + $cond = false; } $op = $tokens->getAndNext(); } elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ... @@ -1270,36 +1272,6 @@ class Template extends Render throw new UnexpectedTokenException($tokens); } - /** - * Parse constant - * #Ns\MyClass::CONST1, #CONST1, #MyClass::CONST1 - * - * @param Tokenizer $tokens - * @return string - * @throws InvalidUsageException - */ - public function parseConst(Tokenizer $tokens) - { - $tokens->get('#'); - $name = $tokens->getNext(T_STRING); - $tokens->next(); - if ($tokens->is(T_NAMESPACE)) { - $name .= '\\'; - $name .= $tokens->getNext(T_STRING); - $tokens->next(); - } - if ($tokens->is(T_DOUBLE_COLON)) { - $name .= '::'; - $name .= $tokens->getNext(T_STRING); - $tokens->next(); - } - if (defined($name)) { - return $name; - } else { - throw new InvalidUsageException("Use undefined constant $name"); - } - } - /** * @param Tokenizer $tokens * @param $name diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index c439331..b007dc8 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -274,6 +274,7 @@ class TemplateTest extends TestCase array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'), array('if: {if false} block1 {else} block2 {/if} end', $a, 'if: block2 end'), array('if: {if null} block1 {else} block2 {/if} end', $a, 'if: block2 end'), + array('if: {if max(2, 4) > 1 && max(2, 3) < 1} block1 {else} block2 {/if} end', $a, 'if: block2 end'), array('if: {if ($val1 || $val0) && $x} block1 {else} block2 {/if} end', $a, 'if: block1 end'), array('if: {if $unexist} block1 {else} block2 {/if} end', $a, 'if: block2 end', Fenom::FORCE_VERIFY), @@ -689,7 +690,7 @@ class TemplateTest extends TestCase public function _testSandbox() { try { - var_dump($this->fenom->compileCode('{$a++~"hi"~time("Y:m:d")}')->getBody()); + var_dump($this->fenom->compileCode('{if max(2, 4) > 1 && max(2, 3) < 1} block1 {else} block2 {/if}')->getBody()); } catch (\Exception $e) { print_r($e->getMessage() . "\n" . $e->getTraceAsString()); }