summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-05-25 12:12:16 +0200
committerKevin Chabowski <kevin@kch42.de>2014-05-25 12:12:16 +0200
commit45d8f703d7cbcdf21248e5ad7aafb6b68054d258 (patch)
treed73acb060121fbe23e9f66e921b553dc40bb43b7 /src
parente21cfaafb0f7ceacca3cb94c15608bcc1148f8a1 (diff)
downloadste-45d8f703d7cbcdf21248e5ad7aafb6b68054d258.tar.gz
ste-45d8f703d7cbcdf21248e5ad7aafb6b68054d258.tar.bz2
ste-45d8f703d7cbcdf21248e5ad7aafb6b68054d258.zip
Fixed backward compatibility with pre 1.0 versions.
Diffstat (limited to 'src')
-rw-r--r--src/ste/STECore.php56
-rw-r--r--src/ste/Scope.php2
-rw-r--r--src/ste/VariableNode.php2
3 files changed, 12 insertions, 48 deletions
diff --git a/src/ste/STECore.php b/src/ste/STECore.php
index c00bf67..d9a2b8e 100644
--- a/src/ste/STECore.php
+++ b/src/ste/STECore.php
@@ -13,7 +13,7 @@ class STECore {
private $tags;
private $storage_access;
private $cur_tpl_dir;
- private $scope;
+ public $scope;
/*
* Variables: Public variables
@@ -22,11 +22,13 @@ class STECore {
* $blockorder - The order of the blocks (an array)
* $mute_runtime_errors - If true (default) a <RuntimeError> exception will result in no output from the tag, if false a error message will be written to output.
* $fatal_error_on_missing_tag - If true, STE will throw a <FatalRuntimeError> if a tag was called that was not registered, otherwise (default) a regular <RuntimeError> will be thrown and automatically handled by STE (see <$mute_runtime_errors>).
+ * $vars - Variables in the top scope of the template.
*/
public $blocks;
public $blockorder;
public $mute_runtime_errors = true;
public $fatal_error_on_missing_tag = false;
+ public $vars;
/*
* Constructor: __construct
@@ -41,7 +43,9 @@ class STECore {
$this->blockorder = array();
$this->blocks = array();
- $this->set_scope(new Scope(array()));
+ $this->vars = array();
+ $this->scope = new Scope();
+ $this->scope->vars =& $this->vars;
}
/*
@@ -279,64 +283,24 @@ class STECore {
return trim($txt . "") != "";
}
- public function get_scope() {
- return $this->scope;
- }
-
- public function set_scope($scope) {
- $this->scope = $scope;
- }
-
public function make_closure($fx) {
$bound_scope = $this->scope;
return function() use($bound_scope, $fx) {
$args = func_get_args();
$ste = $args[0];
- $prev = $ste->get_scope();
+ $prev = $ste->scope;
$scope = $bound_scope->new_subscope();
- $ste->set_scope($scope);
+ $ste->scope = $scope;
try {
$result = call_user_func_array($fx, $args);
- $ste->set_scope($prev);
+ $ste->scope = $prev;
return $result;
} catch(\Exception $e) {
- $ste->set_scope($prev);
+ $ste->scope = $prev;
throw $e;
}
};
}
-
- public function __get($name) {
- if($name === "vars") {
- return $this->scope;
- }
-
- $trace = debug_backtrace();
- trigger_error(
- 'Undefined property via __get(): ' . $name .
- ' in ' . $trace[0]['file'] .
- ' on line ' . $trace[0]['line'],
- E_USER_NOTICE);
- return NULL;
- }
-
- public function __set($name, $val) {
- if($name !== "vars") {
- $trace = debug_backtrace();
- trigger_error(
- 'Undefined property via __set(): ' . $name .
- ' in ' . $trace[0]['file'] .
- ' on line ' . $trace[0]['line'],
- E_USER_NOTICE);
- return;
- }
-
- if(is_array($val)) {
- foreach($val as $k => $v) {
- $this->scope[$k] = $v;
- }
- }
- }
}
diff --git a/src/ste/Scope.php b/src/ste/Scope.php
index 0da2724..26481ac 100644
--- a/src/ste/Scope.php
+++ b/src/ste/Scope.php
@@ -4,7 +4,7 @@ namespace kch42\ste;
class Scope implements \ArrayAccess {
private $parent = NULL;
- private $vars = array();
+ public $vars = array();
private static function parse_name($name) {
$remain = $name;
diff --git a/src/ste/VariableNode.php b/src/ste/VariableNode.php
index b312e81..5fd59ff 100644
--- a/src/ste/VariableNode.php
+++ b/src/ste/VariableNode.php
@@ -6,7 +6,7 @@ class VariableNode extends ASTNode {
public $name;
public $arrayfields = array();
public function transcompile() {
- $varaccess = '@$ste->vars[' . (is_numeric($this->name) ? $this->name : '"' . Misc::escape_text($this->name) . '"'). ']';
+ $varaccess = '@$ste->scope[' . (is_numeric($this->name) ? $this->name : '"' . Misc::escape_text($this->name) . '"'). ']';
foreach($this->arrayfields as $af) {
if((count($af) == 1) and ($af[0] instanceof TextNode) and is_numeric($af[0]->text)) {
$varaccess .= '[' . $af->text . ']';