Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rule.php
1<?php
2
11
12abstract class Rule implements \JsonSerializable
13{
14 protected $title;
15 protected $value;
16 protected $options = [
17 'type' => 'text',
18 'size' => 5,
19 ];
20 protected $groupId = 0;
21
28 public function __construct($title, $value = 0, array $options = null)
29 {
30 $this->title = $title;
31 $this->value = $value;
32 if($options !== null)
33 {
34 $this->options = $options;
35 }
36 }
37
41 public function getTitle()
42 {
43 return $this->title;
44 }
45
49 public function getValue()
50 {
51 return $this->value;
52 }
53
59 public function assignValue($value): bool
60 {
61 if ($this->compare($value))
62 {
63 $this->value = $value;
64 return true;
65 }
66 return false;
67 }
68
74 abstract public function compare($value): bool;
75
79 public function getOptions(): array
80 {
81 return $this->options;
82 }
83
87 public function getGroupId(): int
88 {
89 return $this->groupId;
90 }
91
96 public function setGroupId(int $groupId): Rule
97 {
98 $this->groupId = $groupId;
99 return $this;
100 }
101
106 public function jsonSerialize(): array
107 {
108 $class = get_class($this);
109 $class = substr($class, (int)strrpos($class, '\\') + 1);
110
111 return [
112 'value' => $this->value,
113 'type' => $class,
114 ];
115 }
116}
__construct($title, $value=0, array $options=null)
Definition rule.php:28