honeybadger-io /
honeybadger-laravel
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Honeybadger\HoneybadgerLaravel; |
||
| 4 | |||
| 5 | use Honeybadger\HoneybadgerLaravel\Contracts\Installer as InstallerContract; |
||
| 6 | use Honeybadger\HoneybadgerLaravel\Exceptions\TestException; |
||
| 7 | use Illuminate\Support\Facades\Artisan; |
||
| 8 | use InvalidArgumentException; |
||
| 9 | use sixlive\DotenvEditor\DotenvEditor; |
||
| 10 | |||
| 11 | class Installer implements InstallerContract |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * {@inheritdoc} |
||
| 15 | */ |
||
| 16 | public function writeConfig(array $config, string $filePath): bool |
||
| 17 | { |
||
| 18 | try { |
||
| 19 | $env = new DotenvEditor; |
||
| 20 | $env->load($filePath); |
||
| 21 | } catch (InvalidArgumentException $e) { |
||
| 22 | return false; |
||
| 23 | } |
||
| 24 | |||
| 25 | collect($config)->each(function ($value, $key) use ($env) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 26 | $env->set($key, $value); |
||
| 27 | }); |
||
| 28 | |||
| 29 | return $env->save(); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | public function sendTestException(): array |
||
| 36 | { |
||
| 37 | return app('honeybadger.loud')->notify(new TestException); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | public function publishLaravelConfig(): bool |
||
| 44 | { |
||
| 45 | return Artisan::call('vendor:publish', [ |
||
| 46 | '--tag' => 'honeybadger-config', |
||
| 47 | ]) === 0; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | public function shouldPublishConfig(): bool |
||
| 54 | { |
||
| 55 | return ! file_exists(base_path('config/honeybadger.php')); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | public function publishLumenConfig(string $stubPath = null): bool |
||
| 62 | { |
||
| 63 | if (! is_dir(base_path('config'))) { |
||
| 64 | mkdir(base_path('config')); |
||
| 65 | } |
||
| 66 | |||
| 67 | return copy( |
||
| 68 | $stubPath ?? __DIR__.'/../config/honeybadger.php', |
||
| 69 | base_path('config/honeybadger.php') |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | } |
||
| 73 |