Skip to content

Commit f711c33

Browse files
committed
Доработки
1 parent 8c1fea6 commit f711c33

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

lib/ErrorHandler.php

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,7 @@ public function initialize(array $options)
6363
$this->initTypes($options);
6464

6565
$this->options = $options;
66-
67-
$this->initTypes($options);
68-
69-
$this->options = $options;
70-
$this->options['env'] = $this->options['env'] ?? 'prod';
71-
72-
$this->options['allowed_env'] = $this->options['allowed_env'] ?? ['prod'];
73-
if (count($this->options['allowed_env']) === 0) {
74-
$this->options['allowed_env'] = ['prod'];
75-
}
76-
77-
$this->options['importancy'] = $this->options['importancy'] ?? Notification::IMPORTANCE_URGENT;
66+
$this->initOptions();
7867
}
7968

8069
/**
@@ -109,16 +98,34 @@ public function write($exception, $logType)
10998
}
11099

111100
/**
101+
* Экземпляр notifier.
102+
*
103+
* @return NotifierInterface
104+
*/
105+
private function getNotifier() : NotifierInterface
106+
{
107+
if (!class_exists(\Proklung\Notifier\DI\Services::class)
108+
||
109+
!\Proklung\Notifier\DI\Services::has('notifier')
110+
) {
111+
throw new RuntimeException('Не установлен родительский модуль.');
112+
}
113+
114+
return \Proklung\Notifier\DI\Services::get('notifier');
115+
}
116+
117+
/**
118+
* Отправка уведомлений.
119+
*
112120
* @param Exception $exception
113121
*
114122
* @return void
115123
* @throws Exception
116124
*/
117125
private function send(Exception $exception) : void
118126
{
119-
/** @var NotifierInterface $notifier */
120-
$notifier = \Proklung\Notifier\DI\Services::get('notifier');
121-
$importancy = $this->options['importancy'] ?? Notification::IMPORTANCE_URGENT;
127+
$notifier = $this->getNotifier();
128+
$importancy = $this->options['importancy'];
122129

123130
$envelope = \Proklung\Notifier\DI\Services::getParameter('envelope');
124131
$emails = $envelope['recipients'] ?? [];
@@ -176,6 +183,8 @@ private function has(Exception $e) : bool
176183
}
177184

178185
/**
186+
* Инициализация типов обрабатываемых ошибок.
187+
*
179188
* @param array $options Опции.
180189
*
181190
* @return void
@@ -193,4 +202,21 @@ private function initTypes(array $options) : void
193202
}
194203
}
195204
}
196-
}
205+
206+
/**
207+
* Обработка параметров.
208+
*
209+
* @return void
210+
*/
211+
private function initOptions(): void
212+
{
213+
$this->options['env'] = $this->options['env'] ?? 'prod';
214+
215+
$this->options['allowed_env'] = $this->options['allowed_env'] ?? ['prod'];
216+
if (count($this->options['allowed_env']) === 0) {
217+
$this->options['allowed_env'] = ['prod'];
218+
}
219+
220+
$this->options['importancy'] = $this->options['importancy'] ?? Notification::IMPORTANCE_URGENT;
221+
}
222+
}

0 commit comments

Comments
 (0)