-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YaPro\MonologExt; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
/** | ||
* Исключение позволяет передавать в свойстве 'extraData' дополнительные данные любого типа. Это очень удобно тем, что | ||
* такое исключение переданное в Logger будет обработано Logger-процессором AddInformationAboutExceptionProcessor | ||
* который добавит в log-record указанные 'extraData'. Вот пример использования: | ||
* try { | ||
* throw new ExtraDataException('Exception message', $mixedTypeValue); | ||
* } catch (\Exception $e) { | ||
* $this->logger->error('My error message', [$e]); | ||
* throw $e; | ||
* }. | ||
*/ | ||
class ExtraDataException extends Exception implements ExtraDataExceptionInterface | ||
{ | ||
private mixed $extraData = null; | ||
|
||
public function __construct(string $message = '', mixed $extraData = null, Throwable $previous = null, $code = 0) | ||
{ | ||
// если понадобится использовать $code чаще чем $previous, то сделаем параметры mixed, а тут проверим и | ||
// поменяем местами переменные, чтобы правильно их передать в parent | ||
parent::__construct($message, $code, $previous); | ||
$this->extraData = $extraData; | ||
} | ||
|
||
public function getData(): mixed | ||
{ | ||
return $this->extraData; | ||
} | ||
|
||
public function setData(mixed $extraData): self | ||
{ | ||
$this->extraData = $extraData; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters