/
TextFormatter.php
45 lines (40 loc) · 1.18 KB
/
TextFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Concrete\Core\Error\ErrorList\Formatter;
use Concrete\Core\Error\ErrorList\Error\HtmlAwareErrorInterface;
use Concrete\Core\Error\UserMessageException;
class TextFormatter extends AbstractFormatter
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Error\ErrorList\Formatter\FormatterInterface::render()
*/
public function render()
{
return $this->getText();
}
/**
* Build an plain text string describing the errors.
*
* @return string
*/
public function getText()
{
$lines = [];
if ($this->error->has()) {
foreach ($this->error->getList() as $error) {
if ($error instanceof UserMessageException) {
$errorMessage = $error->getMessage();
} else {
$errorMessage = (string) $error;
}
if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) {
$lines[] = strip_tags($errorMessage);
} else {
$lines[] = $errorMessage;
}
}
}
return implode("\n", $lines);
}
}