This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Plugin.php
83 lines (69 loc) · 2.33 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php namespace Jacob\Horizon;
use Backend\Facades\BackendAuth;
use Backend\Helpers\Backend;
use Backend\Models\User;
use Illuminate\Foundation\AliasLoader;
use Laravel\Horizon\Horizon;
use Laravel\Horizon\HorizonServiceProvider;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
/** @var Backend */
private $backend;
public function __construct($app)
{
parent::__construct($app);
$this->backend = $this->app->make(Backend::class);
}
public function pluginDetails(): array
{
return [
'name' => 'Horizon',
'description' => 'Horizon provides a beautiful dashboard and code-driven configuration for your October powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.',
'author' => 'Jacob',
'iconSvg' => $this->backend->url('jacob/horizon/horizon/icon')
];
}
public function boot(): void
{
$this->app->register(HorizonServiceProvider::class);
AliasLoader::getInstance()->alias('Horizon', Horizon::class);
Horizon::auth(function ($request) {
if (!BackendAuth::check()) {
return false;
}
/** @var User $user */
$user = BackendAuth::getUser();
return $user->isSuperUser() || $user->hasPermission('jacob.horizon.access');
});
if (config('jacob.horizon::dark_mode')) {
Horizon::night();
}
}
public function registerSchedule($schedule): void
{
$schedule->command('horizon:snapshot')->everyFiveMinutes();
}
public function registerPermissions(): array
{
return [
'jacob.horizon.access' => [
'tab' => 'Horizon',
'label' => 'Access to the Horizon dashboard',
'roles' => ['developer'],
],
];
}
public function registerNavigation(): array
{
return [
'horizon' => [
'label' => 'Horizon',
'url' => $this->backend->url('jacob/horizon/horizon'),
'iconSvg' => '/plugins/jacob/horizon/assets/horizon.svg',
'order' => 500,
'permissions' => ['jacob.horizon.access'],
]
];
}
}