Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ProductTokenizer.php
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Integration\Landing
;
4
5
use
Bitrix\Main\Request
;
6
use
Bitrix\Main\Web\Uri
;
7
8
final
class
ProductTokenizer
9
{
10
private
const
PRODUCT_TOKEN =
'productToken'
;
11
12
public
static
function
encode
(array $productIds): string
13
{
14
$productIds = array_unique(array_filter(array_map(
'intval'
, $productIds)));
15
if
(empty($productIds))
16
{
17
return
''
;
18
}
19
20
return
self::encodeBase64Url
(implode(
','
, $productIds));
21
}
22
23
public
static
function
mixIntoUri
(
Uri
$uri, array $productIds):
Uri
24
{
25
$token =
self::encode
($productIds);
26
if
($token ===
''
)
27
{
28
return
$uri;
29
}
30
31
return
$uri->
addParams
([
32
self::PRODUCT_TOKEN => self::encode($productIds),
33
]);
34
}
35
36
public
static
function
decode
(
string
$token): array
37
{
38
if
($token ===
''
)
39
{
40
return
[];
41
}
42
43
$productIds = explode(
','
, self::decodeBase64Url($token));
44
if
(!is_array($productIds) || empty($productIds))
45
{
46
return
[];
47
}
48
49
return
array_unique(array_filter(array_map(
'intval'
, $productIds)));
50
}
51
52
public
static
function
decodeFromRequest
(
Request
$request): ?array
53
{
54
$token = $request->get(self::PRODUCT_TOKEN);
55
if
($token !==
null
&& is_string($token))
56
{
57
return
self::decode
($token);
58
}
59
60
return
null
;
61
}
62
63
public
static
function
encodeBase64Url
(
string
$data): string
64
{
65
return
rtrim(strtr(base64_encode($data),
'+/'
,
'-_'
),
'='
);
66
}
67
68
public
static
function
decodeBase64Url
(
string
$data): string
69
{
70
return
base64_decode(str_pad(strtr($data,
'-_'
,
'+/'
), strlen($data) % 4,
'='
, STR_PAD_RIGHT));
71
}
72
}
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer
Definition
ProductTokenizer.php:9
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\encode
static encode(array $productIds)
Definition
ProductTokenizer.php:12
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\decodeFromRequest
static decodeFromRequest(Request $request)
Definition
ProductTokenizer.php:52
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\decode
static decode(string $token)
Definition
ProductTokenizer.php:36
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\mixIntoUri
static mixIntoUri(Uri $uri, array $productIds)
Definition
ProductTokenizer.php:23
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\encodeBase64Url
static encodeBase64Url(string $data)
Definition
ProductTokenizer.php:63
Bitrix\Catalog\v2\Integration\Landing\ProductTokenizer\decodeBase64Url
static decodeBase64Url(string $data)
Definition
ProductTokenizer.php:68
Bitrix\Main\Request
Definition
request.php:10
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\Web\Uri\addParams
addParams(array $params, $preserveDots=false)
Definition
uri.php:307
Bitrix\Catalog\v2\Integration\Landing
Definition
ProductTokenizer.php:3
modules
catalog
lib
v2
Integration
Landing
ProductTokenizer.php
Создано системой
1.10.0