Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
barcodegenerator.php
1
<?php
2
3
namespace
Bitrix\Sale\PaySystem
;
4
5
use
Bitrix\Main\Loader
;
6
use
Bitrix\UI\Barcode\Barcode
;
7
use
Bitrix\UI\Barcode\BarcodeDictionary
;
8
9
class
BarcodeGenerator
10
{
11
private
Barcode
$barcode;
12
13
private
const
DEFAULT_W = 380;
14
private
const
DEFAULT_H = 380;
15
private
const
DEFAULT_P = 0;
16
private
const
DEFAULT_WQ = 0;
17
18
public
function
__construct
(?array $options =
null
)
19
{
20
if
($this->includeUiModule())
21
{
22
$this->createBarcode($options);
23
}
24
}
25
26
private
function
createBarcode(?array $options =
null
): void
27
{
28
$options =
29
is_null($options)
30
? [
31
'w'
=> self::DEFAULT_W,
32
'h'
=> self::DEFAULT_H,
33
'p'
=> self::DEFAULT_P,
34
'wq'
=> self::DEFAULT_WQ,
35
]
36
: array_intersect_key($options, array_flip(self::getAllowedOptions()))
37
;
38
39
$this->barcode =
new
Barcode
();
40
$this->barcode
41
->type(
BarcodeDictionary::TYPE_QR
)
42
->format(
BarcodeDictionary::FORMAT_PNG
)
43
->options($options)
44
;
45
}
46
47
private
static
function
getAllowedOptions(): array
48
{
49
return
[
50
'w'
,
51
'h'
,
52
'p'
,
53
'wq'
,
54
];
55
}
56
57
public
function
generate
(
string
$data): ?string
58
{
59
$renderData =
null
;
60
61
if
($this->includeUiModule())
62
{
63
$renderData = $this->barcode->render($data);
64
}
65
66
return
$renderData ?:
null
;
67
}
68
69
private
function
includeUiModule(): bool
70
{
71
return
Loader::includeModule(
'ui'
);
72
}
73
}
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Sale\PaySystem\BarcodeGenerator
Definition
barcodegenerator.php:10
Bitrix\Sale\PaySystem\BarcodeGenerator\__construct
__construct(?array $options=null)
Definition
barcodegenerator.php:18
Bitrix\Sale\PaySystem\BarcodeGenerator\generate
generate(string $data)
Definition
barcodegenerator.php:57
Bitrix\UI\Barcode\BarcodeDictionary
Definition
barcodedictionary.php:12
Bitrix\UI\Barcode\BarcodeDictionary\FORMAT_PNG
const FORMAT_PNG
Definition
barcodedictionary.php:13
Bitrix\UI\Barcode\BarcodeDictionary\TYPE_QR
const TYPE_QR
Definition
barcodedictionary.php:32
Bitrix\UI\Barcode\Barcode
Definition
barcode.php:15
Bitrix\Sale\PaySystem
Definition
applepay.php:3
modules
sale
lib
paysystem
barcodegenerator.php
Создано системой
1.10.0