EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
update backend handlebars
Yurii3cd23896b888
diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.phpindex b6ec8450e3..cff77fa088 100644--- a/application/Espo/Core/Htmlizer/Htmlizer.php+++ b/application/Espo/Core/Htmlizer/Htmlizer.php@@ -29,9 +29,9 @@namespace Espo\Core\Htmlizer;+use Closure;use DevTheorem\Handlebars\Handlebars;use DevTheorem\Handlebars\HelperOptions;-use DevTheorem\Handlebars\Options;use DOMDocument;use DOMElement;use DOMException;@@ -109,9 +109,7 @@ class Htmlizer$template = $this->prepare($template, array_keys($helpers));- $options = new Options(helpers: $helpers);-- $renderer = Handlebars::compile($template, $options);+ $renderer = Handlebars::compile($template);$data = $this->prepareRendererData(additionalData: $additionalData,@@ -120,7 +118,7 @@ class Htmlizertemplate: $template,);- $html = $renderer($data);+ $html = $renderer($data, ['helpers' => $helpers]);return $this->postProcessHtml($skipInlineAttachmentHandling, $html);}@@ -268,7 +266,7 @@ class Htmlizer}/**- * @return array<string, callable>+ * @return array<string, Closure>*/private function getHelpers(): array{@@ -339,14 +337,13 @@ class Htmlizerreturn '';}- /** @noinspection PhpUndefinedClassInspection, PhpUndefinedNamespaceInspection */- /** @phpstan-ignore-next-line */- return new DevTheorem\Handlebars\SafeString("?entryPoint=attachment&id=" . $id);+ /** @noinspection PhpFullyQualifiedNameUsageInspection */+ return new \DevTheorem\Handlebars\SafeString("?entryPoint=attachment&id=" . $id);},'pagebreak' => function () {- /** @noinspection PhpUndefinedClassInspection, HtmlUnknownAttribute, PhpUndefinedNamespaceInspection */- /** @phpstan-ignore-next-line */- return new DevTheorem\Handlebars\SafeString('<br pagebreak="true">');+ /** @noinspection PhpFullyQualifiedNameUsageInspection */+ /** @noinspection HtmlUnknownAttribute */+ return new \DevTheorem\Handlebars\SafeString('<br pagebreak="true">');},'imageTag' => function () {$args = func_get_args();@@ -387,9 +384,8 @@ class Htmlizer/** @noinspection HtmlRequiredAltAttribute */$html = "<img src=\"?entryPoint=attachment&id=$id\"$attributesPart>";- /** @noinspection PhpUndefinedNamespaceInspection, PhpUndefinedClassInspection */- /** @phpstan-ignore-next-line */- return new DevTheorem\Handlebars\SafeString($html);+ /** @noinspection PhpFullyQualifiedNameUsageInspection */+ return new \DevTheorem\Handlebars\SafeString($html);},'var' => function () {$args = func_get_args();@@ -480,10 +476,8 @@ class Htmlizer/** @phpstan-ignore-next-line */$paramsString = urlencode(json_encode($params));- /** @noinspection PhpUndefinedNamespaceInspection */- /** @noinspection PhpUndefinedClassInspection */- /** @phpstan-ignore-next-line */- return new DevTheorem\Handlebars\SafeString("<barcodeimage data=\"$paramsString\"/>");+ /** @noinspection PhpFullyQualifiedNameUsageInspection */+ return new \DevTheorem\Handlebars\SafeString("<barcodeimage data=\"$paramsString\"/>");},'ifEqual' => function () {$args = func_get_args();@@ -583,10 +577,8 @@ class Htmlizer$html = '<input type="checkbox" name="1" readonly="true" value="1" style="color: '.$css.'">';}- /** @noinspection PhpUndefinedNamespaceInspection */- /** @noinspection PhpUndefinedClassInspection */- /** @phpstan-ignore-next-line */- return new DevTheorem\Handlebars\SafeString($html);+ /** @noinspection PhpFullyQualifiedNameUsageInspection */+ return new \DevTheorem\Handlebars\SafeString($html);},];@@ -628,8 +620,8 @@ class Htmlizeroptions: (object) $hash,context: $context->scope,rootContext: $rootData,- func: $context->fn,- inverseFunc: $context->inverse,+ func: fn () => $context->fn(),+ inverseFunc: fn () => $context->inverse(),);$helper = $injectableFactory->create($className);diff --git a/application/Espo/Core/Htmlizer/Patch/Runtime.php b/application/Espo/Core/Htmlizer/Patch/Runtime.phpdeleted file mode 100644index 8d89f1c725..0000000000--- a/application/Espo/Core/Htmlizer/Patch/Runtime.php+++ /dev/null@@ -1,453 +0,0 @@-<?php--namespace Espo\Core\Htmlizer\Patch;--use DevTheorem\Handlebars\Handlebars;-use DevTheorem\Handlebars\HelperOptions;-use DevTheorem\Handlebars\RuntimeContext;-use DevTheorem\Handlebars\SafeString;-use DevTheorem\Handlebars\StringObject;--// Patched the `raw` method by adding the float type.--final class Runtime-{- /**- * Output debug info.- */- public static function debug(string $expression, string $runtimeFn, mixed ...$rest): mixed- {- $runtime = self::class;- return call_user_func_array("$runtime::$runtimeFn", $rest);- }-- /**- * Throw exception for missing expression. Only used in strict mode.- */- public static function miss(string $v): void- {- throw new \Exception("Runtime: $v does not exist");- }-- /**- * For {{log}}.- * @param array<mixed> $v- */- public static function lo(array $v): string- {- error_log(var_export($v[0], true));- return '';- }-- /**- * For {{#if}} and {{#unless}}.- *- * @param array<array<mixed>|string|int>|string|\Stringable|int|float|bool|null $v value to be tested- * @param bool $zero include zero as true- *- * @return bool Return true when the value is not null nor false.- */- public static function ifvar(mixed $v, bool $zero = false): bool- {- return $v !== null- && $v !== false- && ($zero || ($v !== 0 && $v !== 0.0))- && $v !== ''- && (!$v instanceof \Stringable || (string) $v !== '')- && (!is_array($v) || count($v) > 0);- }-- /**- * For {{^var}} .- *- * @param array<array<mixed>|string|int>|string|int|bool|null $v value to be tested- *- * @return bool Return true when the value is null or false or empty- */- public static function isec(mixed $v): bool- {- return $v === null || $v === false || (is_array($v) && count($v) === 0);- }-- /**- * HTML encode {{var}} just like handlebars.js- *- * @param array<array<mixed>|string|int>|string|SafeString|int|null $var value to be htmlencoded- */- public static function encq($var): string- {- if ($var instanceof SafeString) {- return (string) $var;- }-- return Handlebars::escapeExpression(static::raw($var));- }-- /**- * Espo comment: Added the float type.- *- * Get string value- *- * @param array<array<mixed>|string|int>|string|int|bool|null $v value to be output- * @param int $ex 1 to return untouched value, default is 0- *- * @return array<array<mixed>|string|int>|string|null The raw value of the specified variable- */- public static function raw(array|string|int|float|bool|null $v, int $ex = 0): string|array|null- {- if ($ex) {- return $v;- }-- if ($v === true) {- return 'true';- }-- if ($v === false) {- return 'false';- }-- if (is_array($v)) {- if (count(array_diff_key($v, array_keys(array_keys($v)))) > 0) {- return '[object Object]';- } else {- $ret = '';- foreach ($v as $vv) {- $ret .= static::raw($vv) . ',';- }- return substr($ret, 0, -1);- }- }-- return "$v";- }-- /**- * For {{#var}} or {{#each}} .- *- * @param array<array<mixed>|string|int>|string|int|bool|null|\Traversable<string, mixed> $v value for the section- * @param array<string>|null $bp block parameters- * @param array<array<mixed>|string|int>|string|int|null $in input data with current scope- * @param bool $each true when rendering #each- * @param \Closure $cb callback function to render child context- * @param \Closure|null $else callback function to render child context when {{else}}- */- public static function sec(RuntimeContext $cx, mixed $v, ?array $bp, mixed $in, bool $each, \Closure $cb, ?\Closure $else = null): string- {- $push = $in !== $v || $each;-- $isAry = is_array($v) || ($v instanceof \ArrayObject);- $isTrav = $v instanceof \Traversable;- $loop = $each;- $keys = null;- $last = null;- $isObj = false;-- if ($isAry && $else !== null && count($v) === 0) {- return $else($cx, $in);- }-- // #var, detect input type is object or not- if (!$loop && $isAry) {- $keys = array_keys($v);- $loop = (count(array_diff_key($v, array_keys($keys))) == 0);- $isObj = !$loop;- }-- if (($loop && $isAry) || $isTrav) {- if ($each && !$isTrav) {- // Detect input type is object or not when never done once- if ($keys == null) {- $keys = array_keys($v);- $isObj = (count(array_diff_key($v, array_keys($keys))) > 0);- }- }- $ret = [];- $cx = clone $cx;- if ($push) {- $cx->scopes[] = $in;- }- $i = 0;- $oldSpvar = $cx->spVars ?? [];- $cx->spVars = array_merge(['root' => $oldSpvar['root'] ?? null], $oldSpvar, ['_parent' => $oldSpvar]);- if (!$isTrav) {- $last = count($keys) - 1;- }-- $isSparceArray = $isObj && (count(array_filter(array_keys($v), 'is_string')) == 0);-- foreach ($v as $index => $raw) {- $cx->spVars['first'] = ($i === 0);- $cx->spVars['last'] = ($i == $last);- $cx->spVars['key'] = $index;- $cx->spVars['index'] = $isSparceArray ? $index : $i;- $i++;- if (isset($bp[0])) {- $raw = static::merge($raw, [$bp[0] => $raw]);- }- if (isset($bp[1])) {- $raw = static::merge($raw, [$bp[1] => $index]);- }- $ret[] = $cb($cx, $raw);- }-- if ($isObj) {- unset($cx->spVars['key']);- } else {- unset($cx->spVars['last']);- }- unset($cx->spVars['index'], $cx->spVars['first']);-- if ($push) {- array_pop($cx->scopes);- }- return join('', $ret);- }-- if ($each) {- return ($else !== null) ? $else($cx, $in) : '';- }-- if ($isAry) {- if ($push) {- $cx->scopes[] = $in;- }- $ret = $cb($cx, $v);- if ($push) {- array_pop($cx->scopes);- }- return $ret;- }-- if ($v === true) {- return $cb($cx, $in);- }-- if ($v !== null && $v !== false) {- return $cb($cx, $v);- }-- if ($else !== null) {- return $else($cx, $in);- }-- return '';- }-- /**- * For {{#with}} .- *- * @param array<array<mixed>|string|int>|string|int|bool|null $v value to be the new context- * @param array<string>|null $bp block parameters- * @param array<array<mixed>|string|int>|\stdClass|null $in input data with current scope- * @param \Closure $cb callback function to render child context- * @param \Closure|null $else callback function to render child context when {{else}}- */- public static function wi(RuntimeContext $cx, mixed $v, ?array $bp, array|\stdClass|null $in, \Closure $cb, ?\Closure $else = null): string- {- if (isset($bp[0])) {- $v = static::merge($v, [$bp[0] => $v]);- }-- if ($v === false || $v === null || (is_array($v) && count($v) === 0)) {- return $else ? $else($cx, $in) : '';- }-- if ($v === $in) {- $ret = $cb($cx, $v);- } else {- $cx->scopes[] = $in;- $ret = $cb($cx, $v);- array_pop($cx->scopes);- }-- return $ret;- }-- /**- * Get merged context.- *- * @param array<array<mixed>|string|int>|object|string|int|null $a the context to be merged- * @param array<array<mixed>|string|int>|string|int|null $b the new context to overwrite- *- * @return array<array<mixed>|string|int>|string|int the merged context object- */- public static function merge(mixed $a, mixed $b): mixed- {- if (is_array($b)) {- if ($a === null) {- return $b;- } elseif (is_array($a)) {- return array_merge($a, $b);- } else {- if (!is_object($a)) {- $a = new StringObject($a);- }- foreach ($b as $i => $v) {- $a->$i = $v;- }- }- }- return $a;- }-- /**- * For {{> partial}} .- *- * @param string $p partial name- * @param array<array<mixed>|string|int>|string|int|null $v value to be the new context- */- public static function p(RuntimeContext $cx, string $p, $v, int $pid, string $sp): string- {- $pp = ($p === '@partial-block') ? $p . ($pid > 0 ? $pid : $cx->partialId) : $p;-- if (!isset($cx->partials[$pp])) {- throw new \Exception("Runtime: the partial $p could not be found");- }-- $cx = clone $cx;- $cx->partialId = ($p === '@partial-block') ? ($pid > 0 ? $pid : ($cx->partialId > 0 ? $cx->partialId - 1 : 0)) : $pid;-- return $cx->partials[$pp]($cx, static::merge($v[0][0], $v[1]), $sp);- }-- /**- * For {{#* inlinepartial}} .- *- * @param string $p partial name- * @param \Closure $code the compiled partial code- */- public static function in(RuntimeContext $cx, string $p, \Closure $code): void- {- $cx->partials[$p] = $code;- }-- /**- * For single custom helpers.- *- * @param string $ch the name of custom helper to be executed- * @param array<array<mixed>|string|int> $vars variables for the helper- * @param array<string,array<mixed>|string|int> $_this current rendering context for the helper- */- public static function hbch(RuntimeContext $cx, string $ch, array $vars, mixed &$_this): mixed- {- if (isset($cx->blParam[0][$ch])) {- return $cx->blParam[0][$ch];- }-- $options = new HelperOptions(- name: $ch,- hash: $vars[1],- fn: function () { return ''; },- inverse: function () { return ''; },- blockParams: 0,- scope: $_this,- data: $cx->spVars,- );-- return static::exch($cx, $ch, $vars, $options);- }-- /**- * For block custom helpers.- *- * @param string $ch the name of custom helper to be executed- * @param array<array<mixed>|string|int> $vars variables for the helper- * @param array<string,array<mixed>|string|int> $_this current rendering context for the helper- * @param bool $inverted the logic will be inverted- * @param \Closure|null $cb callback function to render child context- * @param \Closure|null $else callback function to render child context when {{else}}- */- public static function hbbch(RuntimeContext $cx, string $ch, array $vars, mixed &$_this, bool $inverted, ?\Closure $cb, ?\Closure $else = null): mixed- {- $blockParams = 0;- $data = &$cx->spVars;-- if (isset($vars[2])) {- $blockParams = count($vars[2]);- }-- // invert the logic- if ($inverted) {- $tmp = $else;- $else = $cb;- $cb = $tmp;- }-- $fn = function ($context = null, $data = null) use ($cx, $_this, $cb, $vars) {- $cx = clone $cx;- $old_spvar = $cx->spVars;- if (isset($data['data'])) {- $cx->spVars = array_merge(['root' => $old_spvar['root']], $data['data'], ['_parent' => $old_spvar]);- }-- $ex = false;- if (isset($data['blockParams'], $vars[2])) {- $ex = array_combine($vars[2], array_slice($data['blockParams'], 0, count($vars[2])));- array_unshift($cx->blParam, $ex);- } elseif (isset($cx->blParam[0])) {- $ex = $cx->blParam[0];- }-- if ($context === null) {- $ret = $cb($cx, is_array($ex) ? static::merge($_this, $ex) : $_this);- } else {- $cx->scopes[] = $_this;- $ret = $cb($cx, is_array($ex) ? static::merge($context, $ex) : $context);- array_pop($cx->scopes);- }-- if (isset($data['data'])) {- $cx->spVars = $old_spvar;- }- return $ret;- };-- if ($else) {- $inverse = function ($context = null) use ($cx, $_this, $else) {- if ($context === null) {- $ret = $else($cx, $_this);- } else {- $cx->scopes[] = $_this;- $ret = $else($cx, $context);- array_pop($cx->scopes);- }- return $ret;- };- } else {- $inverse = function () {- return '';- };- }-- $options = new HelperOptions(- name: $ch,- hash: $vars[1],- fn: $fn,- inverse: $inverse,- blockParams: $blockParams,- scope: $_this,- data: $data,- );-- return static::exch($cx, $ch, $vars, $options);- }-- /**- * Execute custom helper with prepared options- *- * @param string $ch the name of custom helper to be executed- * @param array<array<mixed>|string|int> $vars variables for the helper- */- public static function exch(RuntimeContext $cx, string $ch, array $vars, HelperOptions $options): mixed- {- $args = $vars[0];- $args[] = $options;-- try {- return ($cx->helpers[$ch])(...$args);- } catch (\Throwable $e) {- throw new \Exception("Runtime: call custom helper '$ch' error: " . $e->getMessage());- }- }-}diff --git a/application/Espo/Resources/defaults/class-aliases.php b/application/Espo/Resources/defaults/class-aliases.phpindex 1b50983fc2..4bb6e7cb9b 100644--- a/application/Espo/Resources/defaults/class-aliases.php+++ b/application/Espo/Resources/defaults/class-aliases.php@@ -29,7 +29,6 @@// Aliases for backward compatibility or patches.$map = [- 'DevTheorem\\Handlebars\\Runtime' => 'Espo\\Core\\Htmlizer\\Patch\\Runtime','Espo\\Core\\ORM\\Repository\\Option\\SaveContext' => 'Espo\\ORM\\Repository\\Option\\SaveContext','Espo\\Core\\Hooks\\Base' => 'Espo\\Core\\Hook\\Deprecations\\BaseHook','Doctrine\\DBAL\\Platforms\\Keywords\\MariaDb102Keywords' => 'Espo\\Core\\Utils\\Database\\Dbal\\Platforms\\Keywords\\MariaDb102Keywords',diff --git a/composer.json b/composer.jsonindex c40bfbfdae..1831973875 100644--- a/composer.json+++ b/composer.json@@ -56,7 +56,7 @@"directorytree/imapengine": "^1.19","zbateson/mail-mime-parser": "^3.0","guzzlehttp/guzzle": "^7.10",- "devtheorem/php-handlebars": "^0.9.9"+ "devtheorem/php-handlebars": "^1.0"},"require-dev": {"phpunit/phpunit": "^11.5",diff --git a/composer.lock b/composer.lockindex e2c4238fa3..15fbff733b 100644--- a/composer.lock+++ b/composer.lock@@ -4,7 +4,7 @@"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies","This file is @generated automatically"],- "content-hash": "af96bcd2ee292e2b37ba362dbdbf96ba",+ "content-hash": "5b50faa25593b8f60e0bb5fc0050844f","packages": [{"name": "async-aws/core",@@ -636,25 +636,26 @@},{"name": "devtheorem/php-handlebars",- "version": "v0.9.9",+ "version": "v1.0.0","source": {"type": "git","url": "https://github.com/devtheorem/php-handlebars.git",- "reference": "7bfbe91b0330cd92dc0abc55585bcc6128b6506b"+ "reference": "59f5bc256bdca286f90917a80d038cb7f000f207"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/devtheorem/php-handlebars/zipball/7bfbe91b0330cd92dc0abc55585bcc6128b6506b",- "reference": "7bfbe91b0330cd92dc0abc55585bcc6128b6506b",+ "url": "https://api.github.com/repos/devtheorem/php-handlebars/zipball/59f5bc256bdca286f90917a80d038cb7f000f207",+ "reference": "59f5bc256bdca286f90917a80d038cb7f000f207","shasum": ""},"require": {+ "devtheorem/php-handlebars-parser": "^1.1.0","php": ">=8.2"},"require-dev": {- "friendsofphp/php-cs-fixer": "^3.87",+ "friendsofphp/php-cs-fixer": "^3.94","jbboehr/handlebars-spec": "dev-master",- "phpstan/phpstan": "^2.1.28",+ "phpstan/phpstan": "^2.1.42","phpunit/phpunit": "^11.5"},"type": "library",@@ -671,25 +672,76 @@{"name": "Theodore Brown","email": "[email protected]"- },- {- "name": "Zordius Chen",- "email": "[email protected]"}],- "description": "A fast, spec-compliant PHP implementation of Handlebars.",+ "description": "A blazing fast, spec-compliant PHP implementation of Handlebars.","keywords": ["compile","handlebars",- "php",+ "mustache",+ "parse","render","template"],"support": {"issues": "https://github.com/devtheorem/php-handlebars/issues",- "source": "https://github.com/devtheorem/php-handlebars/tree/v0.9.9"+ "source": "https://github.com/devtheorem/php-handlebars/tree/v1.0.0"+ },+ "time": "2026-03-23T04:09:08+00:00"+ },+ {+ "name": "devtheorem/php-handlebars-parser",+ "version": "v1.1.0",+ "source": {+ "type": "git",+ "url": "https://github.com/devtheorem/php-handlebars-parser.git",+ "reference": "cd9fcd2a2ea8869378a999ff420625b2c25b9571"+ },+ "dist": {+ "type": "zip",+ "url": "https://api.github.com/repos/devtheorem/php-handlebars-parser/zipball/cd9fcd2a2ea8869378a999ff420625b2c25b9571",+ "reference": "cd9fcd2a2ea8869378a999ff420625b2c25b9571",+ "shasum": ""+ },+ "require": {+ "php": ">=8.2"+ },+ "require-dev": {+ "friendsofphp/php-cs-fixer": "^3.94",+ "ircmaxell/php-yacc": "dev-master",+ "jbboehr/handlebars-spec": "dev-master",+ "phpstan/phpstan": "^2.1.40",+ "phpunit/phpunit": "^11.5"+ },+ "type": "library",+ "autoload": {+ "psr-4": {+ "DevTheorem\\HandlebarsParser\\": "src/"+ }+ },+ "notification-url": "https://packagist.org/downloads/",+ "license": [+ "MIT"+ ],+ "authors": [+ {+ "name": "Theodore Brown",+ "email": "[email protected]"+ }+ ],+ "description": "Parse Handlebars templates to a spec-compliant AST with PHP.",+ "keywords": [+ "ast",+ "handlebars",+ "parse",+ "php",+ "template"+ ],+ "support": {+ "issues": "https://github.com/devtheorem/php-handlebars-parser/issues",+ "source": "https://github.com/devtheorem/php-handlebars-parser/tree/v1.1.0"},- "time": "2025-10-15T19:05:55+00:00"+ "time": "2026-02-25T01:18:54+00:00"},{"name": "directorytree/imapengine",diff --git a/phpstan.neon b/phpstan.neonindex dc7df4293b..e93b00855a 100644--- a/phpstan.neon+++ b/phpstan.neon@@ -8,7 +8,6 @@ parameters:excludePaths:analyse:- application/Espo/Core/Select/SelectManager.php- - application/Espo/Core/Htmlizer/Patch/*- custom/Espo/Modules/*/vendor/*services:-