From e5be4e97ffc41ca3b0386651a626b781a3637a85 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 6 Oct 2023 18:26:22 +0200 Subject: Update for PHP 8.2 --- Mustache/LambdaHelper.php | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Mustache/LambdaHelper.php (limited to 'Mustache/LambdaHelper.php') diff --git a/Mustache/LambdaHelper.php b/Mustache/LambdaHelper.php new file mode 100644 index 0000000..e93dbfa --- /dev/null +++ b/Mustache/LambdaHelper.php @@ -0,0 +1,76 @@ + =}}`. (default: null) + */ + public function __construct(Mustache_Engine $mustache, Mustache_Context $context, $delims = null) + { + $this->mustache = $mustache; + $this->context = $context; + $this->delims = $delims; + } + + /** + * Render a string as a Mustache template with the current rendering context. + * + * @param string $string + * + * @return string Rendered template + */ + public function render($string) + { + return $this->mustache + ->loadLambda((string) $string, $this->delims) + ->renderInternal($this->context); + } + + /** + * Render a string as a Mustache template with the current rendering context. + * + * @param string $string + * + * @return string Rendered template + */ + public function __invoke($string) + { + return $this->render($string); + } + + /** + * Get a Lambda Helper with custom delimiters. + * + * @param string $delims Custom delimiters, in the format `{{= <% %> =}}` + * + * @return Mustache_LambdaHelper + */ + public function withDelimiters($delims) + { + return new self($this->mustache, $this->context, $delims); + } +} -- cgit v1.2.3-55-g7522