Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
randomnumbergenerator.php
1<?
3
7
8Loc::loadMessages(__FILE__);
9
15{
16 protected $length;
17 const TEMPLATE_WORD_RANDOM = 'RANDOM';
18
20 public function setConfig($config)
21 {
22 $this->setFromArrayOrDefault('length', $config, 5, 'int');
23 }
24
26 public function getConfig()
27 {
28 return ['length' => $this->length,];
29 }
30
32 public function parseTemplate($template)
33 {
34 return str_replace(static::getPatternFor(static::TEMPLATE_WORD_RANDOM), $this->generateRandomString(), $template);
35 }
36
38 public static function getTemplateWordsForParse()
39 {
40 return [static::getPatternFor(static::TEMPLATE_WORD_RANDOM)];
41 }
42
46 private function generateRandomString()
47 {
48 return randString($this->length, ['ABCDEFGHIJKLNMOPQRSTUVWXYZ', '0123456789']);
49 }
50
54 public static function getAvailableForType()
55 {
56 return 'DEFAULT';
57 }
58
60 public static function getTemplateWordsSettings()
61 {
62 return [
63 static::getPatternFor(static::TEMPLATE_WORD_RANDOM) =>
64 Loc::getMessage('BITRIX_MAIN_NUMERATOR_GENERATOR_RANDOMNUMBERGENERATOR_WORD_RANDOM'),
65 ];
66 }
67
69 public static function getSettingsFields()
70 {
71 return [
72 [
73 'settingName' => 'length',
74 'type' => 'int',
75 'default' => 5,
76 'title' => Loc::getMessage('TITLE_BITRIX_MAIN_NUMERATOR_GENERATOR_RANDOMNUMBERGENERATOR_LENGTH'),
77 ],
78 ];
79 }
80
82 public function validateConfig($config)
83 {
84 $result = new Result();
85 return $result;
86 }
87}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
setFromArrayOrDefault($value, $config, $default=null, $type=null)