friendship ended with social-app. php is my new best friend
at main 1.3 kB view raw
1<?php declare(strict_types = 1); 2 3namespace Contributte\Logging\Slack\Formatter; 4 5use Throwable; 6 7final class ExceptionPreviousExceptionsFormatter implements IFormatter 8{ 9 10 public function format(SlackContext $context, Throwable $exception, string $priority): SlackContext 11 { 12 $context = clone $context; 13 14 while (($previous = $exception->getPrevious()) !== null) { 15 $attachment = $context->createAttachment(); 16 $attachment->setFallback('Required plain-text summary of the attachment.'); 17 $attachment->setText(sprintf('*Previous exception* (_%s_)', $previous->getMessage())); 18 $attachment->setMarkdown(); 19 20 $message = $attachment->createField(); 21 $message->setTitle(':mag_right: Exception'); 22 $message->setValue(get_class($previous)); 23 24 $message = $attachment->createField(); 25 $message->setTitle(':envelope: Message'); 26 $message->setValue($previous->getMessage()); 27 $message->setShort(); 28 29 $code = $attachment->createField(); 30 $code->setTitle(':1234: Code'); 31 $code->setValue((string) $previous->getCode()); 32 $code->setShort(); 33 34 $file = $attachment->createField(); 35 $file->setTitle(':open_file_folder: File'); 36 $file->setValue('```' . $previous->getFile() . ':' . $previous->getLine() . '```'); 37 38 // Change pointer 39 $exception = $previous; 40 } 41 42 return $context; 43 } 44 45}