1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Support;
- use App\Models\SystemException;
- class AsyncExceptionRecorder
- {
- public function __construct(
- private string $type,
- private string $message,
- private string $file,
- private int $line,
- private string $trace,
- private array $requestData,
- private ?int $userId
- ) {}
- public static function dispatch(...$args): self
- {
- $instance = new static(...$args);
- register_shutdown_function(function () use ($instance) {
- $instance->handle();
- });
- return $instance;
- }
- public function handle(): void
- {
- SystemException::create([
- 'type' => $this->type,
- 'message' => $this->message,
- 'file' => $this->file,
- 'line' => $this->line,
- 'trace' => $this->trace,
- 'request_data' => $this->requestData,
- 'user_id' => $this->userId,
- 'status' => SystemException::STATUS_PENDING,
- ]);
- }
- }
|