| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Spatie\LaravelIgnition\Commands;
|
|
|
4 |
|
|
|
5 |
use Composer\InstalledVersions;
|
|
|
6 |
use Exception;
|
|
|
7 |
use Illuminate\Config\Repository;
|
|
|
8 |
use Illuminate\Console\Command;
|
|
|
9 |
use Illuminate\Log\LogManager;
|
|
|
10 |
use Spatie\FlareClient\Flare;
|
|
|
11 |
use Spatie\FlareClient\Http\Exceptions\BadResponseCode;
|
|
|
12 |
|
|
|
13 |
class TestCommand extends Command
|
|
|
14 |
{
|
|
|
15 |
protected $signature = 'flare:test';
|
|
|
16 |
|
|
|
17 |
protected $description = 'Send a test notification to Flare';
|
|
|
18 |
|
|
|
19 |
protected Repository $config;
|
|
|
20 |
|
|
|
21 |
public function handle(Repository $config): void
|
|
|
22 |
{
|
|
|
23 |
$this->config = $config;
|
|
|
24 |
|
|
|
25 |
$this->checkFlareKey();
|
|
|
26 |
|
|
|
27 |
if (app()->make('log') instanceof LogManager) {
|
|
|
28 |
$this->checkFlareLogger();
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
$this->sendTestException();
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
protected function checkFlareKey(): self
|
|
|
35 |
{
|
|
|
36 |
$message = empty($this->config->get('flare.key'))
|
|
|
37 |
? '❌ Flare key not specified. Make sure you specify a value in the `key` key of the `flare` config file.'
|
|
|
38 |
: '✅ Flare key specified';
|
|
|
39 |
|
|
|
40 |
$this->info($message);
|
|
|
41 |
|
|
|
42 |
return $this;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function checkFlareLogger(): self
|
|
|
46 |
{
|
|
|
47 |
$defaultLogChannel = $this->config->get('logging.default');
|
|
|
48 |
|
|
|
49 |
$activeStack = $this->config->get("logging.channels.{$defaultLogChannel}");
|
|
|
50 |
|
|
|
51 |
if (is_null($activeStack)) {
|
|
|
52 |
$this->info("❌ The default logging channel `{$defaultLogChannel}` is not configured in the `logging` config file");
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
if (! isset($activeStack['channels']) || ! in_array('flare', $activeStack['channels'])) {
|
|
|
56 |
$this->info("❌ The logging channel `{$defaultLogChannel}` does not contain the 'flare' channel");
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if (is_null($this->config->get('logging.channels.flare'))) {
|
|
|
60 |
$this->info('❌ There is no logging channel named `flare` in the `logging` config file');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if ($this->config->get('logging.channels.flare.driver') !== 'flare') {
|
|
|
64 |
$this->info('❌ The `flare` logging channel defined in the `logging` config file is not set to `flare`.');
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
$this->info('✅ The Flare logging driver was configured correctly.');
|
|
|
68 |
|
|
|
69 |
return $this;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
protected function sendTestException(): void
|
|
|
73 |
{
|
|
|
74 |
$testException = new Exception('This is an exception to test if the integration with Flare works.');
|
|
|
75 |
|
|
|
76 |
try {
|
|
|
77 |
app(Flare::class)->sendTestReport($testException);
|
|
|
78 |
$this->info('');
|
|
|
79 |
} catch (Exception $exception) {
|
|
|
80 |
$this->warn('❌ We were unable to send an exception to Flare. ');
|
|
|
81 |
|
|
|
82 |
if ($exception instanceof BadResponseCode) {
|
|
|
83 |
$this->info('');
|
|
|
84 |
$message = 'Unknown error';
|
|
|
85 |
|
|
|
86 |
$body = $exception->response->getBody();
|
|
|
87 |
|
|
|
88 |
if (is_array($body) && isset($body['message'])) {
|
|
|
89 |
$message = $body['message'];
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$this->warn("{$exception->response->getHttpResponseCode()} - {$message}");
|
|
|
93 |
} else {
|
|
|
94 |
$this->warn($exception->getMessage());
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$this->warn('Make sure that your key is correct and that you have a valid subscription.');
|
|
|
98 |
$this->info('');
|
|
|
99 |
$this->info('For more info visit the docs on https://flareapp.io/docs/ignition-for-laravel/introduction');
|
|
|
100 |
$this->info('You can see the status page of Flare at https://status.flareapp.io');
|
|
|
101 |
$this->info('Flare support can be reached at support@flareapp.io');
|
|
|
102 |
|
|
|
103 |
$this->line('');
|
|
|
104 |
$this->line('Extra info');
|
|
|
105 |
$this->table([], [
|
|
|
106 |
['Platform', PHP_OS],
|
|
|
107 |
['PHP', phpversion()],
|
|
|
108 |
['Laravel', app()->version()],
|
|
|
109 |
['spatie/ignition', InstalledVersions::getVersion('spatie/ignition')],
|
|
|
110 |
['spatie/laravel-ignition', InstalledVersions::getVersion('spatie/laravel-ignition')],
|
|
|
111 |
['spatie/flare-client-php', InstalledVersions::getVersion('spatie/flare-client-php')],
|
|
|
112 |
/** @phpstan-ignore-next-line */
|
|
|
113 |
['Curl', curl_version()['version'] ?? 'Unknown'],
|
|
|
114 |
/** @phpstan-ignore-next-line */
|
|
|
115 |
['SSL', curl_version()['ssl_version'] ?? 'Unknown'],
|
|
|
116 |
]);
|
|
|
117 |
|
|
|
118 |
if ($this->output->isVerbose()) {
|
|
|
119 |
throw $exception;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
return;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
$this->info('We tried to send an exception to Flare. Please check if it arrived!');
|
|
|
126 |
}
|
|
|
127 |
}
|