| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class RaygunTarget extends Target |
||
| 12 | { |
||
| 13 | //public $enabled = true; |
||
| 14 | protected ?RaygunComponent $component = null; |
||
| 15 | |||
| 16 | 2 | public function init() |
|
| 17 | { |
||
| 18 | 2 | parent::init(); |
|
| 19 | |||
| 20 | 2 | $this->component = Yii::$app->raygun; |
|
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Exports the log messages to Raygun. |
||
| 25 | * |
||
| 26 | * This method iterates through the collected log messages and sends them to Raygun. |
||
| 27 | * It handles both exceptions and error messages, sending them with appropriate context. |
||
| 28 | */ |
||
| 29 | 1 | public function export() |
|
| 30 | { |
||
| 31 | 1 | foreach ($this->messages as $message) { |
|
| 32 | 1 | [$context, $level, , , $traces] = $message; |
|
| 33 | |||
| 34 | 1 | if ($context instanceof Throwable) { |
|
| 35 | 1 | $this->component?->sendException($context); |
|
| 36 | 1 | } elseif (is_string($context)) { |
|
| 37 | 1 | $this->component?->sendError( |
|
| 38 | 1 | $level, |
|
| 39 | 1 | $context, |
|
| 40 | 1 | $traces[0]['file'] ?? '', |
|
| 41 | 1 | $traces[0]['line'] ?? 0 |
|
| 42 | 1 | ); |
|
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Generates the context information to be logged. |
||
| 49 | * The default implementation will dump user information, system variables, etc. |
||
| 50 | * Here returns an empty string. |
||
| 51 | * |
||
| 52 | * @return string the context information. If an empty string, it means no context information. |
||
| 53 | */ |
||
| 54 | 1 | protected function getContextMessage() |
|
| 57 | } |
||
| 58 | } |
||
| 59 |