This commit is contained in:
bzick 2013-08-06 12:04:23 +04:00
parent 7fb82bd13a
commit 081e30e744
2 changed files with 4 additions and 31 deletions

View File

@ -648,6 +648,8 @@ class Template extends Render
break; break;
} }
$cond = true; $cond = true;
} elseif ($tokens->is(Tokenizer::MACRO_BOOLEAN)) {
$cond = false;
} }
$op = $tokens->getAndNext(); $op = $tokens->getAndNext();
} elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ... } elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ...
@ -1270,36 +1272,6 @@ class Template extends Render
throw new UnexpectedTokenException($tokens); 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 Tokenizer $tokens
* @param $name * @param $name

View File

@ -274,6 +274,7 @@ class TemplateTest extends TestCase
array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'), 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 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 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', array('if: {if ($val1 || $val0) && $x} block1 {else} block2 {/if} end',
$a, 'if: block1 end'), $a, 'if: block1 end'),
array('if: {if $unexist} block1 {else} block2 {/if} end', $a, 'if: block2 end', Fenom::FORCE_VERIFY), 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() public function _testSandbox()
{ {
try { 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) { } catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString()); print_r($e->getMessage() . "\n" . $e->getTraceAsString());
} }