mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Done #80
This commit is contained in:
parent
6b8ddd4ecc
commit
c56623c1a4
@ -282,6 +282,10 @@ class Fenom
|
|||||||
'type' => self::BLOCK_COMPILER,
|
'type' => self::BLOCK_COMPILER,
|
||||||
'open' => 'Fenom\Compiler::ignoreOpen',
|
'open' => 'Fenom\Compiler::ignoreOpen',
|
||||||
'close' => 'Fenom\Compiler::nope'
|
'close' => 'Fenom\Compiler::nope'
|
||||||
|
),
|
||||||
|
'unset' => array(
|
||||||
|
'type' => self::INLINE_COMPILER,
|
||||||
|
'parser' => 'Fenom\Compiler::tagUnset'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1007,4 +1007,19 @@ class Compiler
|
|||||||
{
|
{
|
||||||
$tag->tpl->ignore('ignore');
|
$tag->tpl->ignore('ignore');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag {unset ...}
|
||||||
|
* @param Tokenizer $tokens
|
||||||
|
* @param Tag $tag
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function tagUnset(Tokenizer $tokens, Tag $tag)
|
||||||
|
{
|
||||||
|
$unset = [];
|
||||||
|
while($tokens->valid()) {
|
||||||
|
$unset[] = $tag->tpl->parseVariable($tokens);
|
||||||
|
}
|
||||||
|
return 'unset('.implode(", ", $unset).')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -596,6 +596,14 @@ class TemplateTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function providerUnset() {
|
||||||
|
return array(
|
||||||
|
array('{var $a = 5} {unset $a} {if $a is not set}not set{/if}', 'not set'),
|
||||||
|
array('{var $a = ["b" => 5, "c" => 6]} {unset $a.b} {if $a.b is not set}not set{/if} but c is {$a.c}', 'not set but c is 6'),
|
||||||
|
array('{var $a = ["b" => 5, "c" => 6]} {unset $a.b $a.c} {if $a.b is not set}not set{/if} {if $a.c is not set}not set{/if}', 'not set not set'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function providerTernary()
|
public static function providerTernary()
|
||||||
{
|
{
|
||||||
$a = array(
|
$a = array(
|
||||||
@ -1296,12 +1304,12 @@ class TemplateTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @group sb
|
* @group sb
|
||||||
*/
|
*/
|
||||||
public function testSandbox()
|
public function _testSandbox()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
var_dump(
|
var_dump(
|
||||||
$this->fenom->compileCode(
|
$this->fenom->compileCode(
|
||||||
'{foreach $fff as $k}{/foreach}'
|
'{unset $a $a.c $b}'
|
||||||
)->getBody()
|
)->getBody()
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -1455,6 +1463,15 @@ class TemplateTest extends TestCase
|
|||||||
$this->exec($code.'{if $arr === $vars}equal{/if}', $v, 'equal');
|
$this->exec($code.'{if $arr === $vars}equal{/if}', $v, 'equal');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerUnset
|
||||||
|
* @group unset
|
||||||
|
*/
|
||||||
|
public function testUnset($code, $result)
|
||||||
|
{
|
||||||
|
$this->exec($code, $this->getVars(), $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerCreateVarInvalid
|
* @dataProvider providerCreateVarInvalid
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user