Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
consent.php
1
<?php
2
3
namespace
Bitrix\Sender\Consent
;
4
5
use
Bitrix\Main\Web\Json
;
6
use
Bitrix\Sender\ContactTable
;
7
use
Bitrix\Sender\Transport
;
8
use
Bitrix\Main\ArgumentNullException
;
9
use
Bitrix\Main\Security\Sign\TimeSigner
;
10
15
final
class
Consent
16
{
17
private
const
SALT =
"SENDER_CONSENT_SALT"
;
18
25
private
static
function
getTransport(?
string
$code):
Transport\Adapter
26
{
27
static
$transports = [];
28
if
(!isset($transports[$code]))
29
{
30
$transports[$code] = Transport\Adapter::create($code);
31
}
32
return
$transports[$code];
33
}
34
48
public
static
function
isUnsub
(
string
$status, ?
int
$requests, ?
string
$code): bool
49
{
50
return
Consent::getTransport($code)->isConsentAvailable() &&
51
(
52
$status ===
ContactTable::CONSENT_STATUS_DENY
||
53
Consent::checkIfConsentRequestLimitExceeded
($requests, $code) &&
54
$status !==
ContactTable::CONSENT_STATUS_ACCEPT
55
);
56
}
57
68
public
static
function
checkIfConsentRequestLimitExceeded
(
int
$requests,
string
$code): bool
69
{
70
return
$requests > Consent::getTransport($code)->getConsentMaxRequests();
71
}
72
81
public
static
function
encodeTag
(array $fields): string
82
{
83
if
(isset($fields))
84
{
85
$signer =
new
TimeSigner
();
86
$tagString = Json::encode($fields);
87
return
$signer->sign($tagString,
"+ 4 weeks"
, Consent::SALT);
88
}
89
90
throw
new
ArgumentNullException
(
"fields"
);
91
}
100
public
static
function
decodeTag
(
string
$tag)
101
{
102
$signer =
new
TimeSigner
();
103
$tag = $signer->unsign($tag,static::SALT);
104
return
Json::decode($tag);
105
}
106
}
Bitrix\Main\ArgumentNullException
Definition
exception.php:54
Bitrix\Main\Security\Sign\TimeSigner
Definition
timesigner.php:13
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Sender\Consent\Consent
Definition
consent.php:16
Bitrix\Sender\Consent\Consent\checkIfConsentRequestLimitExceeded
static checkIfConsentRequestLimitExceeded(int $requests, string $code)
Definition
consent.php:68
Bitrix\Sender\Consent\Consent\encodeTag
static encodeTag(array $fields)
Definition
consent.php:81
Bitrix\Sender\Consent\Consent\isUnsub
static isUnsub(string $status, ?int $requests, ?string $code)
Definition
consent.php:48
Bitrix\Sender\Consent\Consent\decodeTag
static decodeTag(string $tag)
Definition
consent.php:100
Bitrix\Sender\ContactTable
Definition
contact.php:43
Bitrix\Sender\ContactTable\CONSENT_STATUS_DENY
const CONSENT_STATUS_DENY
Definition
contact.php:46
Bitrix\Sender\ContactTable\CONSENT_STATUS_ACCEPT
const CONSENT_STATUS_ACCEPT
Definition
contact.php:47
Bitrix\Sender\Message\Adapter
Definition
adapter.php:21
Bitrix\Sender\Consent
Definition
abstractconsentmessagebuilder.php:3
Bitrix\Sender\Transport
Definition
adapter.php:9
modules
sender
lib
consent
consent.php
Создано системой
1.10.0