Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Ddeboer\Imap\Exception; |
| 6 | |
| 7 | abstract class AbstractException extends \RuntimeException |
| 8 | { |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 9 | private const ERROR_LABELS = [ |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 10 | \E_ERROR => 'E_ERROR', |
| 11 | \E_WARNING => 'E_WARNING', |
| 12 | \E_PARSE => 'E_PARSE', |
| 13 | \E_NOTICE => 'E_NOTICE', |
| 14 | \E_CORE_ERROR => 'E_CORE_ERROR', |
| 15 | \E_CORE_WARNING => 'E_CORE_WARNING', |
| 16 | \E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
| 17 | \E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
| 18 | \E_USER_ERROR => 'E_USER_ERROR', |
| 19 | \E_USER_WARNING => 'E_USER_WARNING', |
| 20 | \E_USER_NOTICE => 'E_USER_NOTICE', |
| 21 | \E_STRICT => 'E_STRICT', |
| 22 | \E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', |
| 23 | \E_DEPRECATED => 'E_DEPRECATED', |
| 24 | \E_USER_DEPRECATED => 'E_USER_DEPRECATED', |
| 25 | ]; |
| 26 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 27 | final public function __construct(string $message, int $code = 0, \Throwable $previous = null) |
| 28 | { |
| 29 | $errorType = ''; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 30 | if (isset(self::ERROR_LABELS[$code])) { |
| 31 | $errorType = \sprintf('[%s] ', self::ERROR_LABELS[$code]); |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | $joinString = "\n- "; |
| 35 | $alerts = \imap_alerts(); |
| 36 | $errors = \imap_errors(); |
| 37 | $completeMessage = \sprintf( |
| 38 | "%s%s\nimap_alerts (%s):%s\nimap_errors (%s):%s", |
| 39 | $errorType, |
| 40 | $message, |
| 41 | false !== $alerts ? \count($alerts) : 0, |
| 42 | false !== $alerts ? $joinString . \implode($joinString, $alerts) : '', |
| 43 | false !== $errors ? \count($errors) : 0, |
| 44 | false !== $errors ? $joinString . \implode($joinString, $errors) : '' |
| 45 | ); |
| 46 | |
| 47 | parent::__construct($completeMessage, $code, $previous); |
| 48 | } |
| 49 | } |