summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/index.php9
-rw-r--r--steloader.php16
-rw-r--r--tests/test.php12
3 files changed, 28 insertions, 9 deletions
diff --git a/example/index.php b/example/index.php
index b8a6938..a0aa03c 100644
--- a/example/index.php
+++ b/example/index.php
@@ -2,11 +2,12 @@
# Example program to demonstrate the STE...
-require_once(dirname(__FILE__) . "/../ste.php");
+require_once(dirname(__FILE__) . "/../steloader.php");
+use \kch42\ste;
# Initialize an STECore instance
-$ste = new \ste\STECore(
- new \ste\FilesystemStorageAccess( # The STECore needs a StorageAccess implementation, we are using the FilesystemStorageAccess, which comes with STE.
+$ste = new ste\STECore(
+ new ste\FilesystemStorageAccess( # The STECore needs a StorageAccess implementation, we are using the FilesystemStorageAccess, which comes with STE.
dirname(__FILE__) . "/templates/src", # FilesystemStorageAccess needs a directory, where the Templates are...
dirname(__FILE__) . "/templates/transc" # ...and a directory for the transcompiled templates (write permissions needed).
)
@@ -32,7 +33,7 @@ $ste->register_tag("repeat",
{
$output = "";
if(!is_numeric($params["n"]))
- throw new \ste\RuntimeError("Sorry, but parameter n must be a number...");
+ throw new ste\RuntimeError("Sorry, but parameter n must be a number...");
for($i = 0; $i < $params["n"]; ++$i)
$output .= $sub($ste);
diff --git a/steloader.php b/steloader.php
new file mode 100644
index 0000000..166f52d
--- /dev/null
+++ b/steloader.php
@@ -0,0 +1,16 @@
+<?php
+
+/*
+ * Very simple autoloader for ste. Will only load ste.
+ * Should only be used for the examples and tests in this project.
+ * Use a full-fledged PSR-3 autoloader (e.g. the composer loader) for production!
+ */
+
+function autoload_ste($cl) {
+ $path = explode("\\", $cl);
+ if(($path[0] == "kch42") && ($path[1] == "ste")) {
+ require_once(__DIR__ . "/" . $path[2] . ".php");
+ }
+}
+
+spl_autoload_register("autoload_ste");
diff --git a/tests/test.php b/tests/test.php
index 79fb69d..ed45d3e 100644
--- a/tests/test.php
+++ b/tests/test.php
@@ -1,16 +1,18 @@
<?php
-require(dirname(__FILE__) . "/../ste.php");
+require(dirname(__FILE__) . "/../steloader.php");
require("code.php");
-class TestStorage implements \ste\StorageAccess {
+use \kch42\ste;
+
+class TestStorage implements ste\StorageAccess {
public function load($tpl, &$mode) {
- $mode = \ste\MODE_SOURCE;
+ $mode = ste\StorageAccess::MODE_SOURCE;
return file_get_contents($tpl);
}
public function save($tpl, $data, $mode) {
- if($mode != \ste\MODE_TRANSCOMPILED) {
+ if($mode != ste\StorageAccess::MODE_TRANSCOMPILED) {
return;
}
@@ -18,7 +20,7 @@ class TestStorage implements \ste\StorageAccess {
}
}
-$ste = new \ste\STECore(new TestStorage());
+$ste = new ste\STECore(new TestStorage());
$ste->mute_runtime_errors = false;
test_func($ste);
echo $ste->exectemplate("test.tpl");