*
* Example:
* [ERROR] No record found
*
* In case the FlashMessage object contains also a title, the
* following format is used:
* [SEVERITY]
:
*
* Example:
* [ERROR] An error occurred: No record found
*
* Multiple messages are separated by a new line (LF).
*/
readonly class PlaintextRenderer implements FlashMessageRendererInterface
{
/**
* Render method
*
* @param FlashMessage[] $flashMessages
* @return string Representation of the flash message as plain text
*/
public function render(array $flashMessages): string
{
$messages = [];
foreach ($flashMessages as $flashMessage) {
$message = $flashMessage->getMessage();
if ($flashMessage->getTitle() !== '') {
$message = $flashMessage->getTitle() . ': ' . $message;
}
$messages[] = '[' . $flashMessage->getSeverity()->name . '] ' . $message;
}
return implode(LF, $messages);
}
}