mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add #209: block's accessor $.blocks
This commit is contained in:
parent
3766505e5c
commit
027075d7b5
@ -379,9 +379,11 @@ class Fenom
|
||||
'tpl' => 'Fenom\Accessor::tpl',
|
||||
'version' => 'Fenom\Accessor::version',
|
||||
'const' => 'Fenom\Accessor::constant',
|
||||
'php' => 'Fenom\Accessor::php',
|
||||
'php' => 'Fenom\Accessor::call',
|
||||
'call' => 'Fenom\Accessor::call',
|
||||
'tag' => 'Fenom\Accessor::Tag',
|
||||
'fetch' => 'Fenom\Accessor::Fetch',
|
||||
'fetch' => 'Fenom\Accessor::fetch',
|
||||
'blocks' => 'Fenom\Accessor::blocks',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -138,7 +138,7 @@ class Accessor {
|
||||
* @param Template $tpl
|
||||
* @return string
|
||||
*/
|
||||
public static function php(Tokenizer $tokens, Template $tpl)
|
||||
public static function call(Tokenizer $tokens, Template $tpl)
|
||||
{
|
||||
$callable = array($tokens->skip('.')->need(Tokenizer::MACRO_STRING)->getAndNext());
|
||||
while($tokens->is('.')) {
|
||||
@ -192,4 +192,46 @@ class Accessor {
|
||||
$tokens->skip(')');
|
||||
return '$tpl->getStorage()->fetch('.$name.', '.$vars.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor {$.blocks.name}
|
||||
* Accessor {$.blocks.name.from}
|
||||
* Accessor {$.blocks.name.code}
|
||||
* Accessor {$.blocks.name.use_parent}
|
||||
* Accessor {$.blocks.name.import}
|
||||
* Accessor {$.blocks}
|
||||
* @param Tokenizer $tokens
|
||||
* @param Template $tpl
|
||||
* @return mixed
|
||||
*/
|
||||
public static function blocks(Tokenizer $tokens, Template $tpl)
|
||||
{
|
||||
if($tokens->is('.')) {
|
||||
$name = $tokens->next()->get(Tokenizer::MACRO_STRING);
|
||||
if($tokens->isNext('.')) {
|
||||
$part = $tokens->next()->next()->get(Tokenizer::MACRO_STRING);
|
||||
$tokens->next();
|
||||
if(!isset($tpl->blocks[$name])) {
|
||||
return 'NULL';
|
||||
}
|
||||
switch($part) {
|
||||
case 'code':
|
||||
return var_export($tpl->blocks[$name]["block"], true);
|
||||
case 'from':
|
||||
return var_export($tpl->blocks[$name]["from"], true);
|
||||
case 'use_parent':
|
||||
return var_export($tpl->blocks[$name]["use_parent"], true);
|
||||
case 'import':
|
||||
return var_export($tpl->blocks[$name]["import"], true);
|
||||
default:
|
||||
throw new UnexpectedTokenException($tokens->back());
|
||||
}
|
||||
} else {
|
||||
$tokens->next();
|
||||
return isset($tpl->blocks[$name]) ? 'true' : 'false';
|
||||
}
|
||||
} else {
|
||||
return "array(".implode(",", array_keys($tpl->blocks)).")";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user