diff --git a/ChangeLog.md b/ChangeLog.md
index 5543631..d261a5c 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -3,6 +3,10 @@ Mustache for XP Framework ChangeLog
## ?.?.? / ????-??-??
+## 9.0.0 / 2025-05-04
+
+**Heads up:** Remove deprecated template loader infrastructure, see #8
+ (@thekid)
**Heads up:** Dropped support for PHP < 7.4, see xp-framework/rfc#343
(@thekid)
* Added PHP 8.5 to test matrix - @thekid
diff --git a/src/main/php/com/github/mustache/Context.class.php b/src/main/php/com/github/mustache/Context.class.php
index fa913a8..9b24fbd 100755
--- a/src/main/php/com/github/mustache/Context.class.php
+++ b/src/main/php/com/github/mustache/Context.class.php
@@ -64,9 +64,7 @@ protected function helper($ptr, $segment) {
return $ptr;
} else if (is_object($ptr)) {
return method_exists($ptr, $segment)
- ? function($in, $ctx, $options) use($ptr, $segment) {
- return $ptr->$segment($in, $ctx, $options);
- }
+ ? fn($in, $ctx, $options) => $ptr->$segment($in, $ctx, $options)
: null
;
} else {
diff --git a/src/main/php/com/github/mustache/MustacheEngine.class.php b/src/main/php/com/github/mustache/MustacheEngine.class.php
index 8d37b66..e9255a9 100755
--- a/src/main/php/com/github/mustache/MustacheEngine.class.php
+++ b/src/main/php/com/github/mustache/MustacheEngine.class.php
@@ -1,6 +1,6 @@
templates= $l;
- } else {
- $this->templates= new FromLoader($l);
- }
+ public function withTemplates(Templates $l) {
+ $this->templates= $l;
return $this;
}
diff --git a/src/main/php/com/github/mustache/TemplateLoader.class.php b/src/main/php/com/github/mustache/TemplateLoader.class.php
deleted file mode 100755
index 33f7d99..0000000
--- a/src/main/php/com/github/mustache/TemplateLoader.class.php
+++ /dev/null
@@ -1,20 +0,0 @@
-loader= $loader;
- }
-
- /**
- * Load a template by a given name
- *
- * @param string $name The template name, not including the file extension
- * @return com.github.mustache.templates.Source
- */
- public function source($name) {
- try {
- return new FromStream($name, $this->loader->load($name));
- } catch (TemplateNotFoundException $e) {
- return new NotFound($e->getMessage());
- }
- }
-
- /**
- * Returns available templates
- *
- * @return com.github.mustache.TemplateListing
- */
- public function listing() {
- if ($this->loader instanceof WithListing) {
- return $this->loader->listing();
- } else {
- throw new IllegalAccessException(typeof($this->loader)->toString().' does not provide listing');
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/php/com/github/mustache/templates/Templates.class.php b/src/main/php/com/github/mustache/templates/Templates.class.php
index 833e38a..9acac3e 100755
--- a/src/main/php/com/github/mustache/templates/Templates.class.php
+++ b/src/main/php/com/github/mustache/templates/Templates.class.php
@@ -1,16 +1,14 @@
source= $source;
- $this->tokens= $tokens;
- }
-
- /** @return string */
- public function code() {
-
- // Detour: Tokenize input, concatenating it back into a string
- $this->tokens->returnDelims= true;
- try {
- $s= '';
- while ($this->tokens->hasMoreTokens()) {
- $s.= $this->tokens->nextToken();
- }
- return $s;
- } finally {
- $this->tokens->returnDelims= false;
- }
- }
-
- /**
- * Compiles this source into a template
- *
- * @param com.github.mustache.MustacheParser $parser
- * @param string $start
- * @param string $end
- * @param string $indent
- * @return com.github.mustache.Template
- */
- public function compile($parser, $start, $end, $indent) {
- return new Template($this->source, $parser->parse($this->tokens, $start, $end, $indent));
- }
-}
\ No newline at end of file
diff --git a/src/test/php/com/github/mustache/unittest/DeprecatedLoaderFunctionalityTest.class.php b/src/test/php/com/github/mustache/unittest/DeprecatedLoaderFunctionalityTest.class.php
deleted file mode 100755
index 3a0d09c..0000000
--- a/src/test/php/com/github/mustache/unittest/DeprecatedLoaderFunctionalityTest.class.php
+++ /dev/null
@@ -1,21 +0,0 @@
- $content]);
- Assert::equals($content, Streams::readAll($loader->load('test')));
- }
-
- #[Test, Expect(class: TemplateNotFoundException::class, message: 'Cannot find template not-found')]
- public function load_raises_error_for_nonexistant_templates() {
- (new InMemory())->load('not-found');
- }
-}
\ No newline at end of file
diff --git a/src/test/php/com/github/mustache/unittest/EngineTest.class.php b/src/test/php/com/github/mustache/unittest/EngineTest.class.php
index ec0243b..560f6fb 100755
--- a/src/test/php/com/github/mustache/unittest/EngineTest.class.php
+++ b/src/test/php/com/github/mustache/unittest/EngineTest.class.php
@@ -1,6 +1,6 @@
'.$text.''; };
+ $helper= fn($text) => ''.$text.'';
Assert::equals($engine, $engine->withHelper('bold', $helper));
}
@@ -50,7 +50,7 @@ public function helpers_initially_empty() {
#[Test]
public function helpers_returns_aded_helper() {
- $helper= function($text) { return ''.$text.''; };
+ $helper= fn($text) => ''.$text.'';
$engine= (new MustacheEngine())->withHelper('bold', $helper);
Assert::equals(['bold' => $helper], $engine->helpers);
}
@@ -65,11 +65,7 @@ public function compile_template() {
#[Test]
public function load_template() {
- $loader= newinstance(TemplateLoader::class, [], [
- 'load' => function($name) {
- return new MemoryInputStream('Hello {{name}}');
- }
- ]);
+ $loader= new InMemory(['test' => 'Hello {{name}}']);
Assert::equals(
new Template('test', new NodeList([new TextNode('Hello '), new VariableNode('name')])),
(new MustacheEngine())->withTemplates($loader)->load('test')
diff --git a/src/test/php/com/github/mustache/unittest/HelpersTest.class.php b/src/test/php/com/github/mustache/unittest/HelpersTest.class.php
index f0cf907..435fbb0 100755
--- a/src/test/php/com/github/mustache/unittest/HelpersTest.class.php
+++ b/src/test/php/com/github/mustache/unittest/HelpersTest.class.php
@@ -2,6 +2,7 @@
use com\github\mustache\{MustacheEngine, VariableNode};
use test\{Assert, Test};
+use util\Date;
class HelpersTest {
@@ -25,7 +26,7 @@ public function replace_single_variable() {
Assert::equals(
'Hello World',
$this->render('Hello {{#bold}}{{name}}{{/bold}}', ['name' => 'World'], [
- 'bold' => function($text) { return ''.$text.''; }
+ 'bold' => fn($text) => ''.$text.''
])
);
}
@@ -35,7 +36,7 @@ public function replace_single_variable_with_node() {
Assert::equals(
'Hello World',
$this->render('Hello {{#var}}name{{/var}}', ['name' => 'World'], [
- 'var' => function($in) { return new VariableNode((string)$in); }
+ 'var' => fn($in) => new VariableNode((string)$in)
])
);
}
@@ -46,8 +47,8 @@ public function dot_notation() {
'Hello world, this is BIG',
$this->render('Hello {{#case.lower}}World{{/case.lower}}, this is {{#case.upper}}big{{/case.upper}}', [], [
'case' => [
- 'lower' => function($text) { return strtolower($text); },
- 'upper' => function($text) { return strtoupper($text); }
+ 'lower' => fn($text) => strtolower($text),
+ 'upper' => fn($text) => strtoupper($text)
]
])
);
@@ -71,7 +72,7 @@ public function instance_method_as_helper() {
'My birthday @ 14.12.2013',
$this->render(
'My birthday @ {{#format.date}}{{date}}{{/format.date}}',
- ['date' => new \util\Date('14.12.2013 00:00:00')],
+ ['date' => new Date('14.12.2013 00:00:00')],
['format' => new class() extends Value {
public function date($in, $context, $options) {
return $context->lookup($in->nodeAt(0)->name())->toString("d.m.Y");
@@ -86,9 +87,7 @@ public function log_section() {
Assert::equals(
'Hello [logged: info "Just a test"]',
$this->render('Hello {{#log info}}Just a test{{/log}}', [], [
- 'log' => function($in, $context, $options) {
- return '[logged: '.$options[0].' "'.$in.'"]';
- }
+ 'log' => fn($in, $context, $options) => '[logged: '.$options[0].' "'.$in.'"]'
])
);
}
@@ -98,9 +97,7 @@ public function log_helper() {
Assert::equals(
'Hello [logged: info Just a test]',
$this->render('Hello {{log info "Just a test"}}', [], [
- 'log' => function($in, $context, $options) {
- return '[logged: '.implode(' ', $options).']';
- }
+ 'log' => fn($in, $context, $options) => '[logged: '.implode(' ', $options).']'
])
);
}
diff --git a/src/test/php/com/github/mustache/unittest/ParserExtendingTest.class.php b/src/test/php/com/github/mustache/unittest/ParserExtendingTest.class.php
index ed83527..d9769aa 100755
--- a/src/test/php/com/github/mustache/unittest/ParserExtendingTest.class.php
+++ b/src/test/php/com/github/mustache/unittest/ParserExtendingTest.class.php
@@ -1,8 +1,8 @@
'Willy',
- 'wrapped' => function($text) {
- return ''.$text.'';
- }
+ 'wrapped' => fn($text) => ''.$text.''
]
)
);
@@ -141,9 +139,7 @@ public function lambda_render_inside() {
"{{/wrapped}}\n",
[
'name' => 'Willy',
- 'wrapped' => function(Node $node, Context $context) {
- return ''.strtoupper($node->evaluate($context)).'';
- }
+ 'wrapped' => fn(Node $node, Context $context) => ''.strtoupper($node->evaluate($context)).''
]
)
);
@@ -157,9 +153,7 @@ public function lambda_variable() {
'{{lambda}}',
[
'name' => 'Willy',
- 'lambda' => function(Node $node, Context $context) {
- return '{{name}} is awesome.';
- }
+ 'lambda' => fn(Node $node, Context $context) => '{{name}} is awesome.'
]
)
);
diff --git a/src/test/php/com/github/mustache/unittest/SpecificationTest.class.php b/src/test/php/com/github/mustache/unittest/SpecificationTest.class.php
index 1372b94..4ee7dfc 100755
--- a/src/test/php/com/github/mustache/unittest/SpecificationTest.class.php
+++ b/src/test/php/com/github/mustache/unittest/SpecificationTest.class.php
@@ -3,8 +3,8 @@
use com\github\mustache\{InMemory, MustacheEngine};
use io\collections\iterate\{ExtensionEqualsFilter, FilteredIOCollectionIterator};
use io\collections\{FileCollection, FileElement};
-use text\json\StreamInput;
use test\{Assert, Test, TestCase, Values};
+use text\json\StreamInput;
/**
* Executes the Mustache specifications
@@ -54,10 +54,7 @@ public function specification_met($name, $test) {
// Select correct lambda
if (isset($test['data']['lambda'])) {
- $php= $test['data']['lambda']['php'];
- $test['data']['lambda']= function($text, $context) use($php) {
- return eval($php);
- };
+ $test['data']['lambda']= fn($text, $context) => eval($test['data']['lambda']['php']);
}
// Render, and assert result