aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-04 02:57:01 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-04 02:57:01 -0400
commitfd35fcc863735eee0b3740b39161b54bb77ed946 (patch)
tree1d58c237ce3c76e0e8b68b88b678390d172508f6
parent141ff66fda9abb3e1cfaa9bca8701707324ee60f (diff)
downloadluigi-template-fd35fcc863735eee0b3740b39161b54bb77ed946.tar.bz2
luigi-template-fd35fcc863735eee0b3740b39161b54bb77ed946.zip
use RunContext
-rw-r--r--php/src/Template.php28
1 files changed, 14 insertions, 14 deletions
diff --git a/php/src/Template.php b/php/src/Template.php
index 69e3fb8..5bd9872 100644
--- a/php/src/Template.php
+++ b/php/src/Template.php
@@ -66,6 +66,10 @@ final class RunContext {
}
};
+namespace Luigi\Parser;
+
+use \Luigi\RunContext;
+
final class TemplateFilter {
private $name,
$args;
@@ -88,13 +92,9 @@ final class TemplateFilter {
}
};
-namespace Luigi\Parser;
-
-use Luigi\RunContext;
-use Luigi
abstract class Token {
- public function run(array $args, array $filters) : string;
+ public function run(RunContext $ctx) : string;
};
final class LiteralToken extends Token {
@@ -104,7 +104,7 @@ final class LiteralToken extends Token {
$this->val = $val;
}
- public function run(array &$args, array &$filters) : string {
+ public function run(RunContext $ctx) : string {
return $this->val;
}
};
@@ -118,18 +118,18 @@ final class FilterToken extends Token {
$this->filters = $filters;
}
- public function run(array &$args, array &$filters) : string {
+ public function run(RunContext &$ctx) : string {
if (!isset($args[$this->key])) {
throw new UnknownKeyError($this->key);
}
# get initial value
- $r = $args[$this->key];
+ $r = $ctx->args[$this->key];
if ($this->filters && count($this->filters) > 0) {
# pass value through filters
- $r = array_reduce($this->filters, function($r, $f) use (&$args, &$filters) {
- return $f->run($r, $args, $filters);
+ $r = array_reduce($this->filters, function($r, $f) use (&$ctx) {
+ return $f->run($r, $ctx->args, $ctx->filters);
}, $r);
}
@@ -327,11 +327,11 @@ final class Template {
}
public function run(array $args = []) : string {
- # php sucks
- $me = $this;
+ # create run context
+ $ctx = new RunContext($args, $this->filters);
- return join('', array_map(function($token) use ($me, $args) {
- return $token->run($args, $this->filters);
+ return join('', array_map(function($token) use (&$ctx) {
+ return $token->run($ctx);
}, $this->tokens));
}