blob: eb8ea85024f9677f8556588ca994c23b49d80ab6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
declare(strict_types=1);
class FreshRSS_FilterAction {
/** @var array<string>|null */
private ?array $actions = null;
/** @param array<string> $actions */
private function __construct(private readonly FreshRSS_BooleanSearch $booleanSearch, array $actions) {
$this->_actions($actions);
}
public function booleanSearch(): FreshRSS_BooleanSearch {
return $this->booleanSearch;
}
/** @return array<string> */
public function actions(): array {
return $this->actions ?? [];
}
/** @param array<string> $actions */
public function _actions(?array $actions): void {
if (is_array($actions)) {
$this->actions = array_unique($actions);
} else {
$this->actions = null;
}
}
/** @return array{'search'?:string,'actions'?:array<string>} */
public function toJSON(): array {
if (is_array($this->actions) && $this->booleanSearch != null) {
return [
'search' => $this->booleanSearch->getRawInput(),
'actions' => $this->actions,
];
}
return [];
}
/** @param array|mixed|null $json */
public static function fromJSON($json): ?FreshRSS_FilterAction {
if (is_array($json) && !empty($json['search']) && !empty($json['actions']) && is_array($json['actions'])) {
return new FreshRSS_FilterAction(new FreshRSS_BooleanSearch($json['search']), $json['actions']);
}
return null;
}
}
|