Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
secretfield.php
1<?php
10
12
14{
15 protected $secretLength = 20;
16
22 public function __construct($name, $parameters = [])
23 {
24 //the order of modifiers is important
25 $this->addSaveDataModifier([$this, 'encode']);
26
27 parent::__construct($name, $parameters);
28
29 $this->addFetchDataModifier([$this, 'decode']);
30
31 if(isset($parameters['secret_length']))
32 {
33 $this->configureSecretLength($parameters['secret_length']);
34 }
35
36 $this->configureDefaultValue([$this, 'getRandomBytes']);
37 }
38
42 public function configureSecretLength($length)
43 {
44 if($length > 0)
45 {
46 $this->secretLength = (int)$length;
47 }
48 }
49
55 public function encode($data)
56 {
57 return base64_encode($data);
58 }
59
65 public function decode($data)
66 {
67 return base64_decode($data);
68 }
69
73 public function getRandomBytes()
74 {
75 return Security\Random::getBytes($this->secretLength);
76 }
77}
addFetchDataModifier($modifier)
Definition field.php:344
addSaveDataModifier($modifier)
Definition field.php:420
__construct($name, $parameters=[])