-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDiffOpAdd.php
109 lines (96 loc) · 1.76 KB
/
DiffOpAdd.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare( strict_types = 1 );
namespace Diff\DiffOp;
/**
* Represents an addition.
* This means the value was not present in the "old" object but is in the new.
*
* @since 0.1
*
* @license BSD-3-Clause
* @author Jeroen De Dauw < [email protected] >
*/
class DiffOpAdd extends AtomicDiffOp {
/** @var mixed */
private $newValue;
/**
* @see DiffOp::getType
*
* @since 0.1
*
* @return string
*/
public function getType(): string {
return 'add';
}
/**
* @since 0.1
*
* @param mixed $newValue
*/
public function __construct( $newValue ) {
$this->newValue = $newValue;
}
/**
* @since 0.1
*
* @return mixed
*/
public function getNewValue() {
return $this->newValue;
}
/**
* @see Serializable::serialize
*
* @since 0.1
*
* @return string|null
*/
#[\ReturnTypeWillChange]
public function serialize() {
return serialize( $this->newValue );
}
/**
* @since 3.3.0
*
* @return array
*/
public function __serialize(): array {
return [ $this->newValue ];
}
/**
* @see Serializable::unserialize
*
* @since 0.1
*
* @param string $serialization
*/
#[\ReturnTypeWillChange]
public function unserialize( $serialization ) {
$this->newValue = unserialize( $serialization );
}
/**
* @since 3.3.0
*
* @param array $data
*/
public function __unserialize( $data ): void {
[ $this->newValue ] = $data;
}
/**
* @see DiffOp::toArray
*
* @since 0.5
*
* @param callable|null $valueConverter optional callback used to convert any
* complex values to arrays.
*
* @return array
*/
public function toArray( ?callable $valueConverter = null ): array {
return [
'type' => $this->getType(),
'newvalue' => $this->objectToArray( $this->newValue, $valueConverter ),
];
}
}