Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
errorservice.php
1
<?php
2
3
namespace
Bitrix\Location\Infrastructure\Service
;
4
5
use
Bitrix\Location\Common\BaseService
;
6
use
Bitrix\Location\Exception\ErrorCodes
;
7
use
Bitrix\Location\Infrastructure\Service\Config\Container
;
8
use
Bitrix\Location\Infrastructure\Service\LoggerService\LogLevel
;
9
use
Bitrix\Main\Error
;
10
use
Bitrix\Main\ErrorCollection
;
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Main\SystemException
;
13
14
Loc::loadMessages
(__FILE__);
15
20
final
class
ErrorService
extends
BaseService
21
{
23
protected
static
$instance
;
24
26
protected
$errorCollection
;
27
29
protected
$logErrors
;
30
32
protected
$throwExceptionOnError
;
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
{
69
return
$this->errorCollection
;
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
88
public
function
setThrowExceptionOnError
(
bool
$throwExceptionOnError
): void
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
}
Bitrix\Location\Common\BaseService
Definition
baseservice.php:12
Bitrix\Location\Exception\ErrorCodes
Definition
errorcodes.php:6
Bitrix\Location\Infrastructure\Service\Config\Container
Definition
container.php:8
Bitrix\Location\Infrastructure\Service\Config\Container\get
get($id)
Definition
container.php:16
Bitrix\Location\Infrastructure\Service\ErrorService
Definition
errorservice.php:21
Bitrix\Location\Infrastructure\Service\ErrorService\addError
addError(Error $error)
Definition
errorservice.php:38
Bitrix\Location\Infrastructure\Service\ErrorService\__construct
__construct(Container $config)
Definition
errorservice.php:105
Bitrix\Location\Infrastructure\Service\ErrorService\$logErrors
$logErrors
Definition
errorservice.php:29
Bitrix\Location\Infrastructure\Service\ErrorService\logError
logError(Error $error)
Definition
errorservice.php:59
Bitrix\Location\Infrastructure\Service\ErrorService\clearErrors
clearErrors()
Definition
errorservice.php:72
Bitrix\Location\Infrastructure\Service\ErrorService\setLogErrors
setLogErrors(bool $logErrors)
Definition
errorservice.php:80
Bitrix\Location\Infrastructure\Service\ErrorService\setThrowExceptionOnError
setThrowExceptionOnError(bool $throwExceptionOnError)
Definition
errorservice.php:88
Bitrix\Location\Infrastructure\Service\ErrorService\getErrors
getErrors()
Definition
errorservice.php:67
Bitrix\Location\Infrastructure\Service\ErrorService\$errorCollection
$errorCollection
Definition
errorservice.php:26
Bitrix\Location\Infrastructure\Service\ErrorService\hasErrors
hasErrors()
Definition
errorservice.php:96
Bitrix\Location\Infrastructure\Service\ErrorService\$instance
static $instance
Definition
errorservice.php:23
Bitrix\Location\Infrastructure\Service\ErrorService\$throwExceptionOnError
$throwExceptionOnError
Definition
errorservice.php:32
Bitrix\Location\Infrastructure\Service\LoggerService\LogLevel
Definition
loglevel.php:5
Bitrix\Location\Infrastructure\Service\LoggerService\LogLevel\ERROR
const ERROR
Definition
loglevel.php:7
Bitrix\Main\ErrorCollection
Definition
errorcollection.php:14
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Error\getMessage
getMessage()
Definition
error.php:62
Bitrix\Main\Error\getCode
getCode()
Definition
error.php:53
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Location\Infrastructure\Service
modules
location
lib
infrastructure
service
errorservice.php
Создано системой
1.10.0