Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
errorservice.php
1<?php
2
4
13
14Loc::loadMessages(__FILE__);
15
20final class ErrorService extends BaseService
21{
23 protected static $instance;
24
27
29 protected $logErrors;
30
33
38 public function addError(Error $error): void
39 {
40 $this->errorCollection[] = $error;
41
42 if($this->logErrors)
43 {
44 $this->logError($error);
45 }
46
47 if($this->throwExceptionOnError)
48 {
49 throw new SystemException(
50 Loc::getMessage('LOCATION_ISTRUCTURE_ERRORSERVICE_ERROR'),
51 ErrorCodes::ERRORSERVICE_ERROR_WAS_HAPPENED
52 );
53 }
54 }
55
59 protected function logError(Error $error): void
60 {
61 LoggerService::getInstance()->log(LogLevel::ERROR, $message = $error->getMessage(), $error->getCode());
62 }
63
67 public function getErrors(): ErrorCollection
68 {
70 }
71
72 public function clearErrors(): void
73 {
74 $this->errorCollection->clear();
75 }
76
80 public function setLogErrors(bool $logErrors): void
81 {
82 $this->logErrors = $logErrors;
83 }
84
89 {
90 $this->throwExceptionOnError = $throwExceptionOnError;
91 }
92
96 public function hasErrors(): bool
97 {
98 return $this->errorCollection->count() > 0;
99 }
100
105 protected function __construct(Container $config)
106 {
107 parent::__construct($config);
108 $this->logErrors = $config->get('logErrors');
109 $this->throwExceptionOnError = $config->get('throwExceptionOnError');
110 $this->errorCollection = new ErrorCollection();
111 }
112}
setThrowExceptionOnError(bool $throwExceptionOnError)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29