|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facade\Ignition\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Illuminate\Log\LogManager; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Config\Repository; |
|
9
|
|
|
|
|
10
|
|
|
class TestCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
protected $signature = 'flare:test'; |
|
13
|
|
|
|
|
14
|
|
|
protected $description = 'Send a test notification to Flare'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var \Illuminate\Config\Repository */ |
|
17
|
|
|
protected $config; |
|
18
|
|
|
|
|
19
|
|
|
public function handle(Repository $config) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->config = $config; |
|
22
|
|
|
|
|
23
|
|
|
$this->checkFlareKey(); |
|
24
|
|
|
|
|
25
|
|
|
if (app()->make('log') instanceof LogManager) { |
|
26
|
|
|
$this->checkFlareLogger(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$this->sendTestException(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function checkFlareKey() |
|
33
|
|
|
{ |
|
34
|
|
|
$message = empty($this->config->get('flare.key')) |
|
35
|
|
|
? '❌ Flare key not specified. Make sure you specify a value in the `key` key of the `flare` config file.' |
|
36
|
|
|
: '✅ Flare key specified'; |
|
37
|
|
|
|
|
38
|
|
|
$this->info($message); |
|
39
|
|
|
|
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function checkFlareLogger() |
|
44
|
|
|
{ |
|
45
|
|
|
$defaultLogChannel = $this->config->get('logging.default'); |
|
46
|
|
|
|
|
47
|
|
|
$activeStack = $this->config->get("logging.channels.{$defaultLogChannel}"); |
|
48
|
|
|
|
|
49
|
|
|
if (is_null($activeStack)) { |
|
50
|
|
|
$this->info("❌ The default logging channel `{$defaultLogChannel}` is not configured in the `logging` config file"); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (! isset($activeStack['channels']) || ! in_array('flare', $activeStack['channels'])) { |
|
54
|
|
|
$this->info("❌ The logging channel `{$defaultLogChannel}` does not contain the 'flare' channel"); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (is_null($this->config->get('logging.channels.flare'))) { |
|
58
|
|
|
$this->info('❌ There is no logging channel named `flare` in the `logging` config file'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ($this->config->get('logging.channels.flare.driver') !== 'flare') { |
|
62
|
|
|
$this->info('❌ The `flare` logging channel defined in the `logging` config file is not set to `flare`.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->info('✅ The Flare logging driver was configured correctly.'); |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function sendTestException() |
|
71
|
|
|
{ |
|
72
|
|
|
$testException = new Exception('This is an exception to test if the integration with Flare works.'); |
|
73
|
|
|
|
|
74
|
|
|
try { |
|
75
|
|
|
app('flare.client')->sendTestReport($testException); |
|
76
|
|
|
$this->info(PHP_EOL); |
|
77
|
|
|
} catch (Exception $exception) { |
|
78
|
|
|
$this->warn('❌ We were unable to send an exception to Flare. Make sure that your key is correct and that you have a valid subscription. '.PHP_EOL.PHP_EOL.'For more info visit the docs on installing Flare in a Laravel project: https://flareapp.io/docs/ignition-for-laravel/introduction'); |
|
79
|
|
|
|
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->info('We tried to send an exception to Flare. Please check if it arrived!'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|