Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BaseAction.php
1<?php
3
4abstract class BaseAction
5{
6 protected const JS_COMMAND = '';
7 protected array $params = [];
8
14 public function setParams(array $params, bool $prepared = false): void
15 {
16 if (!$prepared)
17 {
18 $params = static::enrichParams($params);
19 }
20 $this->params = $params;
21 }
22
23 public function getParams(): array
24 {
25 return $this->params;
26 }
27
28 abstract public function execute(bool $undo = true): bool;
29 abstract public static function enrichParams(array $params): array;
30
35 public function delete(): bool
36 {
37 return true;
38 }
39
44 public function isNeedPush(): bool
45 {
46 // todo: compare valuebefore||valueafter (see examples in some actions)
47 return !empty($this->params);
48 }
49
54 public function getJsCommand(bool $undo = true): array
55 {
56 return [
57 'command' => static::JS_COMMAND,
58 'params' => $this->params,
59 ];
60 }
61
66 public static function getJsCommandName(): string
67 {
68 return static::JS_COMMAND;
69 }
70
77 public static function compareParams(array $oldParams, array $newParams): bool
78 {
79 return $oldParams === $newParams;
80 }
81}
static compareParams(array $oldParams, array $newParams)
setParams(array $params, bool $prepared=false)