-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadata.php
75 lines (65 loc) · 1.5 KB
/
Metadata.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
<?php
/*
* This file is part of the broadway/broadway package.
*
* (c) Qandidate.com <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Broadway\Domain;
use Broadway\Serializer\SerializableInterface;
/**
* Metadata adding extra information to the DomainMessage.
*/
class Metadata implements SerializableInterface
{
private $values = [];
/**
* @param array $values
*/
public function __construct(array $values = [])
{
$this->values = $values;
}
/**
* Merges the values of this and the other instance.
*
* @param Metadata $otherMetadata
*
* @return Metadata a new instance
*/
public function merge(Metadata $otherMetadata)
{
$mergedValues = array_merge($this->values, $otherMetadata->values);
return new Metadata($mergedValues);
}
/**
* {@inheritDoc}
*/
public function serialize()
{
return $this->values;
}
/**
* Helper method to construct an instance containing the key and value.
*
* @param mixed $key
* @param mixed $value
*
* @return Metadata
*/
public static function kv($key, $value)
{
return new Metadata([$key => $value]);
}
/**
* @param array $data
*
* @return Metadata
*/
public static function deserialize(array $data)
{
return new Metadata($data);
}
}