Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accesschecker.php
1<?php
9
13
14
15Loc::loadMessages(__FILE__);
16
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}
setError(Error $error, $offset=null)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getError($code=self::ERR_CODE_VIEW)
static checkViewAccess(ErrorCollection $collection, User $user=null)
static addError(ErrorCollection $collection, $code=self::ERR_CODE_VIEW)