Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accesschecker.php
1
<?php
8
namespace
Bitrix\Sender\Security
;
9
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Main\ErrorCollection
;
13
14
15
Loc::loadMessages
(__FILE__);
16
21
class
AccessChecker
22
{
23
const
ERR_CODE_VIEW
=
'ERR_VIEW'
;
24
const
ERR_CODE_EDIT
=
'ERR_EDIT'
;
25
const
ERR_CODE_NOT_FOUND
=
'ERR_NOT_FOUND'
;
26
33
public
static
function
getMessage
($code)
34
{
35
$message =
Loc::getMessage
(
'SENDER_SECURITY_ACCESS_CHECKER_'
.mb_strtoupper($code));
36
return
$message ?:
'Unknown error.'
;
37
}
38
45
public
static
function
getError
($code = self::ERR_CODE_VIEW)
46
{
47
return
new
Error
(self::getMessage($code));
48
}
49
57
public
static
function
addError
(
ErrorCollection
$collection, $code = self::ERR_CODE_VIEW)
58
{
59
$collection->
setError
(self::getError($code));
60
}
61
69
public
static
function
checkViewAccess
(
ErrorCollection
$collection,
User
$user =
null
)
70
{
71
$user = $user ?:
User::current
();
72
if
(!$user->canView())
73
{
74
$collection->
setError
(
new
Error
(
75
self::getMessage(self::ERR_CODE_VIEW),
76
self::ERR_CODE_VIEW
77
));
78
return
false
;
79
}
80
81
return
true
;
82
}
83
}
Bitrix\Main\ErrorCollection
Definition
errorcollection.php:14
Bitrix\Main\ErrorCollection\setError
setError(Error $error, $offset=null)
Definition
errorcollection.php:65
Bitrix\Main\Error
Definition
error.php:14
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\Sender\Security\AccessChecker
Definition
accesschecker.php:22
Bitrix\Sender\Security\AccessChecker\ERR_CODE_EDIT
const ERR_CODE_EDIT
Definition
accesschecker.php:24
Bitrix\Sender\Security\AccessChecker\getError
static getError($code=self::ERR_CODE_VIEW)
Definition
accesschecker.php:45
Bitrix\Sender\Security\AccessChecker\getMessage
static getMessage($code)
Definition
accesschecker.php:33
Bitrix\Sender\Security\AccessChecker\ERR_CODE_NOT_FOUND
const ERR_CODE_NOT_FOUND
Definition
accesschecker.php:25
Bitrix\Sender\Security\AccessChecker\checkViewAccess
static checkViewAccess(ErrorCollection $collection, User $user=null)
Definition
accesschecker.php:69
Bitrix\Sender\Security\AccessChecker\ERR_CODE_VIEW
const ERR_CODE_VIEW
Definition
accesschecker.php:23
Bitrix\Sender\Security\AccessChecker\addError
static addError(ErrorCollection $collection, $code=self::ERR_CODE_VIEW)
Definition
accesschecker.php:57
Bitrix\Sender\Security\User
Definition
user.php:24
Bitrix\Sender\Security\User\current
static current()
Definition
user.php:46
Bitrix\Sender\Security
Definition
access.php:3
modules
sender
lib
security
accesschecker.php
Создано системой
1.10.0