encodia/laravel-something-wrong

用于Laravel的简单包,用于通知处理错误、异常等

1.0.0 2024-05-16 13:28 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

Total Downloads

用于Laravel的简单包,用于通知处理错误、异常等。

注意:此包仍在开发中,当前其功能非常有限。

安装

您可以通过composer安装此包

composer require encodia/laravel-something-wrong

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-something-wrong-config"

用法

注意:当前版本仅支持Bugsnag

这意味着您通知的所有内容都将使用Bugsnag底层发送通知。

位置

通常,您将在服务类构造函数中注入Encodia\SomethingWrong

use \Encodia\SomethingWrong;

class MyService {
    private SomethingWrong $somethingWrong;

    public function __construct(SomethingWrong $somethingWrong)
    {        
        $this->somethingWrong = $somethingWrong;
    }
    
    public function doSomething(): void
    {
        // ...
        $this->somethingWrong
            ->exception(
                new \Exception("This wasn't supposed to happen, so let's notify it!")
        );
        
        // ...        
    }
}

    

如果您愿意,可以使用它的外观

use \Encodia\SomethingWrong\Facades\SomethingWrong;

// ...
SomethingWrong::exception(
    new \Exception("This wasn't supposed to happen, so let's notify it!")
);

如何使用

您可以通过不传递任何其他详细信息来通知一个简单的异常

SomethingWrong::exception(
    new \Exception("Something wrong happened!")
);

如果您需要添加任何详细信息,只需将数组作为第二个参数传递

SomethingWrong::exception(
    new \Exception("Something wrong happened!"),
    [
        'foo' => 'bar',
        'path' => 'a/b/c',
        'user' => auth()->user,
    ],
);

测试

composer test

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。