ewb:iterator.explode(glue: 'constant:LF')} * * * {as} * */ class ExplodeViewHelper extends AbstractViewHelper { protected string $method = 'explode'; public function initializeArguments(): void { $this->registerArgument( 'as', 'string', 'Template variable name to assign; if not specified the ViewHelper returns the variable instead.', ); $this->registerArgument('content', 'string', 'String to be exploded by glue'); $this->registerArgument( 'glue', 'string', 'String used as glue in the string to be exploded. Use glue value of "constant:NAMEOFCONSTANT" ' . '(fx "constant:LF" for linefeed as glue)', false, ',' ); } public function render(): mixed { $content = $this->arguments['content'] ?? $this->renderChildren(); $glue = $this->resolveGlue($this->arguments); $content = call_user_func_array($this->method, [$glue, $content]); $as = $this->arguments['as']; if ($as !== null) { $templateVariableContainer = $this->renderingContext->getVariableProvider(); $templateVariableContainer->add($as, $content); $output = $this->renderChildren(); $templateVariableContainer->remove($as); } else { $output = $content; } return $output; } protected function resolveGlue(array $arguments): string { $glue = $arguments['glue']; if (str_contains($glue, ':') && strlen($glue) > 1) { // glue contains a special type identifier, resolve the actual glue [$type, $value] = explode(':', $glue); $glue = match ($type) { 'constant' => constant($value), default => $value, }; } return $glue; } }