1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Julius Härtl <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Deck\Activity; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class ChangeSet implements \JsonSerializable { |
28
|
|
|
|
29
|
|
|
private $before; |
30
|
|
|
private $after; |
31
|
|
|
private $diff = false; |
32
|
|
|
|
33
|
|
|
public function __construct($before = null, $after = null) { |
34
|
|
|
if ($before !== null) { |
35
|
|
|
$this->setBefore($before); |
36
|
|
|
} |
37
|
|
|
if ($after !== null) { |
38
|
|
|
$this->setAfter($after); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function enableDiff() { |
43
|
|
|
$this->diff = true; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getDiff() { |
47
|
|
|
return $this->diff; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function setBefore($before) { |
51
|
|
|
if (is_object($before)) { |
52
|
|
|
$this->before = clone $before; |
53
|
|
|
} else { |
54
|
|
|
$this->before = $before; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function setAfter($after) { |
59
|
|
|
if (is_object($after)) { |
60
|
|
|
$this->after = clone $after; |
61
|
|
|
} else { |
62
|
|
|
$this->after = $after; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getBefore() { |
67
|
|
|
return $this->before; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getAfter() { |
71
|
|
|
return $this->after; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Specify data which should be serialized to JSON |
76
|
|
|
* |
77
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
78
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
79
|
|
|
* which is a value of any type other than a resource. |
80
|
|
|
* @since 5.4.0 |
81
|
|
|
*/ |
82
|
|
|
public function jsonSerialize() { |
83
|
|
|
return [ |
84
|
|
|
'before' => $this->getBefore(), |
85
|
|
|
'after' => $this->getAfter(), |
86
|
|
|
'diff' => $this->getDiff(), |
87
|
|
|
'type' => get_class($this->before) |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|