Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
abstractconfigfield.php
1<?php
2
4
5
6abstract class AbstractConfigField implements IConfigField
7{
8 protected const URL_PATTERN = '%^((https://)|(www\.)|(http://))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i';
9
10 protected abstract static function checkValueFields($value) : bool;
11
12 protected static function getFields() : array
13 {
14 return ['enabled'];
15 }
16
17 protected static function filter(array $values)
18 {
19 $fields = static::getFields();
20 return array_filter($values,function($key) use ($fields) {
21 return in_array($key,$fields);
22 },ARRAY_FILTER_USE_KEY);
23 }
24
25 protected static function setDefaultFields($value)
26 {
27 return $value;
28 }
29
30 protected static function setEnabled($value)
31 {
32 $value['enabled'] = true;
33 return $value;
34 }
35 static function prepareValue($value)
36 {
37 if(is_array($value))
38 {
39 if(!static::checkEnabled($value))
40 {
41 return static::filter(static::setDefaultFields(static::setEnabled($value)));
42 }
43 elseif($value['enabled'])
44 {
45 return $value;
46 }
47 }
48 return static::getDefaultValue();
49 }
53 static function getDefaultValue()
54 {
55 return (static::required() ? ['enabled' => false] : null);
56 }
57
58 protected static function checkEnabled($value) : bool
59 {
60 return array_key_exists('enabled',$value) && is_bool($value['enabled']);
61 }
65 static function checkValue($value): bool
66 {
67 if(!isset($value) && !static::required())
68 {
69 return true;
70 }
71 elseif(is_array($value) && static::checkEnabled($value))
72 {
73 return (!$value['enabled']? true : static::checkValueFields($value));
74 }
75 return false;
76 }
77}