Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
componentcontroller.php
1
<?php
8
namespace
Bitrix\Main\UserConsent\Internals
;
9
10
use
Bitrix\Main\Context
;
11
use
Bitrix\Main\HttpRequest
;
12
use
Bitrix\Main\Web\Json
;
13
use
Bitrix\Main\Localization\Loc
;
14
15
Loc::loadMessages
(__FILE__);
16
17
abstract
class
ComponentController
18
{
19
protected
$errors
= array();
20
protected
$action
=
null
;
21
protected
$responseData
= array();
22
protected
$requestData
= array();
23
25
protected
$request
= array();
26
27
abstract
protected
function
getActions
();
28
abstract
protected
function
checkPermissions
();
29
30
protected
function
prepareRequestData
()
31
{
32
33
}
34
35
protected
function
giveResponse
()
36
{
37
global $APPLICATION;
38
$APPLICATION->restartBuffer();
39
40
header(
'Content-Type:application/json; charset=UTF-8'
);
41
echo Json::encode(
42
$this->responseData + array(
43
'error'
=> $this->
hasErrors
(),
44
'text'
=> implode(
'<br>'
, $this->errors),
45
)
46
);
47
48
\CMain::finalActions();
49
exit;
50
}
51
52
protected
function
getActionCall
()
53
{
54
return
array($this, $this->action);
55
}
56
57
protected
function
hasErrors
()
58
{
59
return
!empty($this->errors);
60
}
61
62
protected
function
check
()
63
{
64
if
(!$this->
checkPermissions
())
65
{
66
$this->errors[] =
Loc::getMessage
(
'MAIN_PERMISSION_DENIED'
);
67
}
68
if
(!in_array($this->action, $this->
getActions
()))
69
{
70
$this->errors[] =
'Action "'
. $this->action .
'" not found.'
;
71
}
72
elseif(!check_bitrix_sessid() || !$this->request->isPost())
73
{
74
$this->errors[] =
'Security error.'
;
75
}
76
elseif(!is_callable($this->
getActionCall
()))
77
{
78
$this->errors[] =
'Action method "'
. $this->action .
'" not found.'
;
79
}
80
81
return
!$this->
hasErrors
();
82
}
83
89
public
function
exec
()
90
{
91
$this->request =
Context::getCurrent
()->getRequest();
92
$this->action = $this->request->get(
'action'
);
93
94
$this->
prepareRequestData
();
95
96
if
($this->
check
())
97
{
98
call_user_func_array($this->
getActionCall
(), array($this->requestData));
99
}
100
$this->
giveResponse
();
101
}
102
}
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\HttpRequest
Definition
httprequest.php:20
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\UserConsent\Internals\ComponentController
Definition
componentcontroller.php:18
Bitrix\Main\UserConsent\Internals\ComponentController\checkPermissions
checkPermissions()
Bitrix\Main\UserConsent\Internals\ComponentController\getActionCall
getActionCall()
Definition
componentcontroller.php:52
Bitrix\Main\UserConsent\Internals\ComponentController\$requestData
$requestData
Definition
componentcontroller.php:22
Bitrix\Main\UserConsent\Internals\ComponentController\prepareRequestData
prepareRequestData()
Definition
componentcontroller.php:30
Bitrix\Main\UserConsent\Internals\ComponentController\check
check()
Definition
componentcontroller.php:62
Bitrix\Main\UserConsent\Internals\ComponentController\$action
$action
Definition
componentcontroller.php:20
Bitrix\Main\UserConsent\Internals\ComponentController\hasErrors
hasErrors()
Definition
componentcontroller.php:57
Bitrix\Main\UserConsent\Internals\ComponentController\$responseData
$responseData
Definition
componentcontroller.php:21
Bitrix\Main\UserConsent\Internals\ComponentController\$errors
$errors
Definition
componentcontroller.php:19
Bitrix\Main\UserConsent\Internals\ComponentController\exec
exec()
Definition
componentcontroller.php:89
Bitrix\Main\UserConsent\Internals\ComponentController\getActions
getActions()
Bitrix\Main\UserConsent\Internals\ComponentController\$request
$request
Definition
componentcontroller.php:25
Bitrix\Main\UserConsent\Internals\ComponentController\giveResponse
giveResponse()
Definition
componentcontroller.php:35
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Main\Context
Definition
culture.php:9
Bitrix\Main\UserConsent\Internals
Definition
agreement.php:8
modules
main
lib
userconsent
internals
componentcontroller.php
Создано системой
1.10.0