diff --git a/docs/syntax.md b/docs/syntax.md index 763eea0..e9de09f 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -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 diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index 64f0685..146bf66 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -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(); diff --git a/src/Fenom/Render.php b/src/Fenom/Render.php index 649dc06..36f4a8c 100644 --- a/src/Fenom/Render.php +++ b/src/Fenom/Render.php @@ -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'; + } } diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index af2cae2..3057d63 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -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); }