mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #39
This commit is contained in:
parent
7fb82bd13a
commit
081e30e744
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user