summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-05-25 12:13:00 +0200
committerKevin Chabowski <kevin@kch42.de>2014-05-25 12:13:00 +0200
commit8c92f0fce1493651e5bacecdbdfc1bd32327c279 (patch)
tree4accdcbc21bec4ea264f7dd71d7664b9c2d3a1f4
parent5ce8ff18911ae6f38da12e8df157943d5a7d81ce (diff)
parent533c1285c05665cfcd8794152b87e97fe2885675 (diff)
downloadste-1.0.2.tar.gz
ste-1.0.2.tar.bz2
ste-1.0.2.zip
Merge branch 'develop'1.0.2
-rw-r--r--src/ste/FilesystemStorageAccess.php4
-rw-r--r--src/ste/STECore.php58
-rw-r--r--src/ste/Scope.php2
-rw-r--r--src/ste/VariableNode.php2
4 files changed, 14 insertions, 52 deletions
diff --git a/src/ste/FilesystemStorageAccess.php b/src/ste/FilesystemStorageAccess.php
index ef29404..cdbce8b 100644
--- a/src/ste/FilesystemStorageAccess.php
+++ b/src/ste/FilesystemStorageAccess.php
@@ -62,9 +62,7 @@ class FilesystemStorageAccess implements StorageAccess {
public function save($tpl, $data, $mode) {
$fn = (($mode == StorageAccess::MODE_SOURCE) ? $this->sourcedir : $this->transcompileddir) . "/" . $tpl . (($mode == StorageAccess::MODE_TRANSCOMPILED) ? ".php" : "");
@mkdir(dirname($fn), 0777, true);
- if(file_put_contents($fn, "<?php
-
-// File: FilesystemStorageAccess.php \$transcompile_fx = $data; ?>") === false) {
+ if(file_put_contents($fn, "<?php\n\$transcompile_fx = $data; ?>") === false) {
throw new CantSaveTemplate("Unable to save template.");
}
}
diff --git a/src/ste/STECore.php b/src/ste/STECore.php
index c00bf67..35a92d5 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;
}
/*
@@ -276,15 +280,7 @@ class STECore {
* true/false.
*/
public function evalbool($txt) {
- return trim($txt . "") != "";
- }
-
- public function get_scope() {
- return $this->scope;
- }
-
- public function set_scope($scope) {
- $this->scope = $scope;
+ return trim(@(string)$txt) != "";
}
public function make_closure($fx) {
@@ -293,50 +289,18 @@ class STECore {
$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 . ']';