Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
consent.php
1<?php
2
4
10
15final 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 (
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}