From dbeb38a5cccb8ebce587de427e2c53de13c0a099 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Mon, 1 Nov 2021 13:48:05 +1300 Subject: [PATCH] Change: update syntax of template block class --- src/Template/Parser/TemplateBlock.php | 43 +++++++++------------------ 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/Template/Parser/TemplateBlock.php b/src/Template/Parser/TemplateBlock.php index aa3d0dd..90738dd 100755 --- a/src/Template/Parser/TemplateBlock.php +++ b/src/Template/Parser/TemplateBlock.php @@ -3,34 +3,27 @@ namespace Moo\Template\Parser; /** - * Class TemplateBlock + * Class TemplateBlock. */ class TemplateBlock { /** - * Collection of section arguments - * - * @var array + * Collection of section arguments. */ - protected static $arguments = []; + protected static array $arguments = []; /** - * Unique name for content argument - * - * @var string + * Unique name for content argument. */ - protected static $contentName = '{{___CONTENT___}}'; + protected static string $contentName = '{{___CONTENT___}}'; /** - * Provide a template tag in template. Its similar implementation to <% include %> - * - * @param array $res - * @return string + * Provide a template tag in template. Its similar implementation to <% include %>. */ - public static function template($res) + public static function template(array $res): string { // Create unique name for content - static::$contentName = uniqid('__CONTENT__'); + static::$contentName = uniqid('__CONTENT__', true); // Name of content argument $content = static::$contentName; @@ -39,7 +32,7 @@ public static function template($res) $arguments = '['; // First the values from '<% arg %>' foreach (static::$arguments as $name => $value) { - $arguments .= "'" . $name . "' => " . $value . ','; + $arguments .= "'".$name."' => ".$value.','; } // Construct 'Content' argument that would hold the content from the body of '<% template %>' @@ -59,7 +52,7 @@ public static function template($res) // Clear the values from the static storage static::$arguments = []; - // Render template by lookup code + // Render template by lookup code, else argument is string, then render template by name if ($res['Arguments'][0]['ArgumentMode'] === 'lookup') { $template = str_replace('$$FINAL', 'XML_val', $res['Arguments'][0]['php']); $php = <<getItem(), {$arguments}, \$scope ); PHP; - } - // If argument is string, then render template by name - else { + } else { $template = trim($res['Arguments'][0]['text'], "'"); $php = <<