-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugin.php
74 lines (64 loc) · 2.25 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
<?php
namespace Winter\Ignition;
use Config;
use Event;
use Illuminate\Support\Facades\Request;
use Spatie\LaravelIgnition\Facades\Flare;
use Spatie\LaravelIgnition\IgnitionServiceProvider;
use Spatie\LaravelIgnition\Renderers\ErrorPageRenderer;
use Spatie\LaravelIgnition\Renderers\IgnitionExceptionRenderer;
use System\Classes\PluginBase;
use Winter\Storm\Exception\AjaxException;
use Winter\Storm\Exception\ApplicationException;
/**
* Ignition Plugin Information File
*/
class Plugin extends PluginBase
{
public $elevated = true;
/**
* Returns information about this plugin.
*/
public function pluginDetails(): array
{
return [
'name' => 'winter.ignition::lang.plugin.name',
'description' => 'winter.ignition::lang.plugin.description',
'author' => 'winter',
'icon' => 'icon-leaf'
];
}
/**
* Register method, called when the plugin is first registered.
*/
public function register(): void
{
if (Config::get('app.debug', false)) {
$this->registerIgnition();
}
}
/**
* Register Ignition
*/
protected function registerIgnition(): void
{
// Mirror the configuration over to the appropriate keys
Config::set('ignition', Config::get('winter.ignition::ignition'));
Config::set('flare', Config::get('winter.ignition::flare'));
// Register the package service provider & alias
$this->app->register(IgnitionServiceProvider::class);
$this->app->alias('Flare', Flare::class);
// Register the custom Winter context data middleware
Flare::registerMiddleware(\Winter\Ignition\Middleware\AddWinterContextData::class);
// Register the exception handler
Event::listen('exception.beforeRender', function ($exception, $httpCode, $request) {
// Let winter handle rendering exceptions in AJAX requests
// TODO: Check if this still allows reporting of these exceptions to Flare
if (Request::ajax()) {
return;
}
$handler = new IgnitionExceptionRenderer(new ErrorPageRenderer());
return $handler->render($exception);
}, PHP_INT_MAX - 20);
}
}