-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
144 lines (130 loc) · 4.3 KB
/
controller.php
File metadata and controls
144 lines (130 loc) · 4.3 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace Concrete\Package\ErrorNotifier;
use Concrete\Core\Application\Application;
use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Database\EntityManager\Provider\ProviderInterface;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Package\Package;
/**
* The package controller.
*
* Manages the package installation, update and start-up.
*/
class Controller extends Package implements ProviderInterface
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::$appVersionRequired
*/
protected $appVersionRequired = '8.5.2';
/**
* The unique handle that identifies the package.
*
* @var string
*/
protected $pkgHandle = 'error_notifier';
/**
* The package version.
*
* @var string
*/
protected $pkgVersion = '1.2.3';
/**
* @var string
*/
private $upgradingFrom = '';
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::getPackageName()
*/
public function getPackageName()
{
return t('Error Notifier');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::getPackageDescription()
*/
public function getPackageDescription()
{
return t('Send errors and warnings to Slack and Telegram.');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Database\EntityManager\Provider\ProviderInterface::getDrivers()
*/
public function getDrivers()
{
return [];
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::install()
*/
public function install()
{
parent::install();
$this->installContentFile('config/install.xml');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::upgradeCoreData()
*/
public function upgradeCoreData()
{
$entity = $this->getPackageEntity();
$this->upgradingFrom = $entity ? (string) $entity->getPackageVersion() : '';
parent::upgradeCoreData();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::upgrade()
*/
public function upgrade()
{
parent::upgrade();
$this->installContentFile('config/install.xml');
if ($this->upgradingFrom && version_compare($this->upgradingFrom, '1.0.1') <= 0) {
$config = $this->app->make(Repository::class);
$config->save('error_notifier::options.interceptExceptions', (bool) $config->get('error_notifier::options.whoops'));
$config->save('error_notifier::options.interceptLogWrites', (bool) $config->get('error_notifier::options.exceptionsLog'));
}
}
public function on_start()
{
$this->app->bindIf(Options::class, static function() { return app(Options\Config::class); }, true);
if ($this->app->bound('Whoops\Run')) {
$this->app->make('Whoops\Run')->pushHandler($this->app->make(Handler\Whoops::class));
} elseif ($this->app->bound('Concrete\Core\Error\Handling\ErrorHandler')) {
$this->app->make('Concrete\Core\Error\Handling\ErrorHandler')->addExceptionListener(function(\Throwable $x) {
$handler = $this->app->make(Handler\ThrowableHandler::class);
return $handler($x);
});
}
if (!class_exists('Concrete\Core\Logging\LoggerFactory')) {
$this->app->extend('log/exceptions', static function ($logger, Application $app) {
if ($logger instanceof \Monolog\Logger) {
$logger->pushHandler($app->make(Handler\Monolog::class));
}
return $logger;
});
} else {
$director = $this->app->make('director');
$dispatcher = method_exists($director, 'getEventDispatcher') ? $director->getEventDispatcher() : $director;
$dispatcher->addListener('on_logger_create', function($event) {
$logger = method_exists($event, 'getLogger') ? $event->getLogger() : null;
if ($logger instanceof \Monolog\Logger && $logger->getName() === Channels::CHANNEL_EXCEPTIONS) {
/** @var \Monolog\Logger $logger */
$logger->pushHandler($this->app->make(Handler\Monolog::class));
}
});
}
}
}