This commit is contained in:
bzick 2013-08-12 20:14:35 +04:00
parent 982b284f60
commit 25975a6782
4 changed files with 53 additions and 24 deletions

View File

@ -1,11 +1,11 @@
Syntax [RU]
===========
Fenom have [Smarty](http://www.smarty.net/) like syntax.
Fenom implement [Smarty](http://www.smarty.net/) syntax with some improvements
## Variable
### Get/print value
### Use variables
```smarty
{$foo}
@ -20,7 +20,31 @@ Fenom have [Smarty](http://www.smarty.net/) like syntax.
{$foo.$bar}
{$foo[$bar]}
{$foo->bar}
{$foo->bar()}
{$foo->bar.buz}
```
### System variable
Unnamed system variable starts with `$.` and allow access to global variables and system info:
* `$.get` is `$_GET`.
* `$.post` is `$_POST`.
* `$.cookie` is `$_COOKIE`.
* `$.session` is `$_SESSION`.
* `$.globals` is `$GLOBALS`.
* `$.request` is `$_REQUEST`.
* `$.files` is `$_FILES`.
* `$.server` is `$_SERVER`.
* `$.env` is `$_ENV`.
* `$.tpl.name` returns current template name.
* `$.tpl.schema` returns current schema of the template.
* `$.version` returns version of the Fenom.
* `$.const` paste constant.
```smarty
{if $.get.debug? && $.const.DEBUG}
...
{/if}
```
### Multidimensional value support

View File

@ -33,14 +33,6 @@ class Compiler
public static function tagInclude(Tokenizer $tokens, Template $tpl)
{
$name = false;
// if($tokens->is('[')) {
// $tokens->next();
// if(!$name && $tokens->is(T_CONSTANT_ENCAPSED_STRING)) {
// if($tpl->getStorage()->templateExists($_name = substr($tokens->getAndNext(), 1, -1))) {
// $name = $_name;
// }
// }
// }
$cname = $tpl->parsePlainArg($tokens, $name);
$p = $tpl->parseParams($tokens);
if ($p) { // if we have additionally variables
@ -706,7 +698,7 @@ class Compiler
*/
public static function varOpen(Tokenizer $tokens, Scope $scope)
{
$var = $scope->tpl->parseVariable($tokens, Template::DENY_MODS);
$var = $scope->tpl->parseVar($tokens);
if ($tokens->is('=')) { // inline tag {var ...}
$scope->is_closed = true;
$tokens->next();

View File

@ -235,4 +235,22 @@ class Render extends \ArrayObject
{
throw new \BadMethodCallException("Unknown method " . $method);
}
public function __get($name)
{
if($name == 'info') {
return array(
'name' => $this->_name,
'schema' => $this->_scm,
'time' => $this->_time
);
} else {
return null;
}
}
public function __isset($name)
{
return $name == 'info';
}
}

View File

@ -918,15 +918,16 @@ class Template extends Render
{
$is_var = false;
$vars = array(
'get' => '$_GET',
'post' => '$_POST',
'get' => '$_GET',
'post' => '$_POST',
'session' => '$_SESSION',
'cookie' => '$_COOKIE',
'cookie' => '$_COOKIE',
'request' => '$_REQUEST',
'files' => '$_FILES',
'files' => '$_FILES',
'globals' => '$GLOBALS',
'server' => '$_SERVER',
'env' => '$_ENV',
'server' => '$_SERVER',
'env' => '$_ENV',
'tpl' => '$tpl->info'
);
if ($this->_options & Fenom::DENY_ACCESSOR) {
throw new \LogicException("Accessor are disabled");
@ -948,12 +949,6 @@ class Template extends Render
case 'version':
$var = '\Fenom::VERSION';
break;
case 'tpl':
$var = '$tpl->getName()';
break;
case 'schema':
$var = '$tpl->getScm()';
break;
default:
throw new UnexpectedTokenException($tokens);
}