1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Infinitypaul\LaravelUptime\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Infinitypaul\LaravelUptime\Commands\Traits\CanForce; |
7
|
|
|
use Infinitypaul\LaravelUptime\Endpoint; |
8
|
|
|
|
9
|
|
|
class Status extends Command |
10
|
|
|
{ |
11
|
|
|
use CanForce; |
12
|
|
|
|
13
|
|
|
protected $client; |
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'uptime:status {--F|force}'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command description. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $description = 'Display The Status Of All Endpoint In A Table'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Execute the console command. |
30
|
|
|
* |
31
|
|
|
* @return mixed |
32
|
|
|
*/ |
33
|
|
|
public function handle() |
34
|
|
|
{ |
35
|
|
|
if ($this->isForced()) { |
36
|
|
|
$this->call('uptime:run', ['--force'=> true]); |
37
|
|
|
} |
38
|
|
|
$headers = ['ID', 'URI', 'Frequency', 'Last Checked', 'Human Date', 'Status', 'Response Code']; |
39
|
|
|
|
40
|
|
|
Endpoint::with('statuses')->chunk(100, function ($endpoints) use ($headers) { |
41
|
|
|
$this->table($headers, $endpoints->map(function ($endpoint) { |
42
|
|
|
return array_merge( |
43
|
|
|
$endpoint->only(['id', 'uri', 'frequency']), |
44
|
|
|
$endpoint->status ? $this->getEndpointStatus($endpoint) : [] |
45
|
|
|
); |
46
|
|
|
})->toArray() |
47
|
|
|
); |
48
|
|
|
}); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getEndpointStatus(Endpoint $endpoint) |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
'created_at' => $endpoint->status->created_at, |
|
|
|
|
55
|
|
|
'human_date' => $endpoint->status->created_at->diffForHumans(), |
|
|
|
|
56
|
|
|
'status' => $this->formatStatus($endpoint->status), |
|
|
|
|
57
|
|
|
'status_code' => $endpoint->status->status_code, |
|
|
|
|
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function formatStatus($status) |
62
|
|
|
{ |
63
|
|
|
if ($status->isDown()) { |
64
|
|
|
return '<error>Down</error>'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return '<bg=green;fg=black>Up</>'; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.