1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* tubee |
7
|
|
|
* |
8
|
|
|
* @copyright Copryright (c) 2017-2019 gyselroth GmbH (https://gyselroth.com) |
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tubee\Resource; |
13
|
|
|
|
14
|
|
|
use MongoDB\BSON\ObjectIdInterface; |
15
|
|
|
use MongoDB\BSON\UTCDateTimeInterface; |
16
|
|
|
|
17
|
|
|
abstract class AbstractResource implements ResourceInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Kind. |
21
|
|
|
*/ |
22
|
|
|
public const KIND = 'Resource'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Data. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $resource = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
12 |
|
public function getId(): ObjectIdInterface |
35
|
|
|
{ |
36
|
12 |
|
return $this->resource['_id']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
2 |
|
public function getKind(): string |
43
|
|
|
{ |
44
|
2 |
|
if (isset($this->resource['kind'])) { |
45
|
|
|
return $this->resource['kind']; |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
return static::KIND; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
12 |
|
public function getName(): string |
55
|
|
|
{ |
56
|
12 |
|
if (isset($this->resource['name'])) { |
57
|
12 |
|
return $this->resource['name']; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return (string) $this->resource['_id']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
2 |
|
public function toArray(): array |
67
|
|
|
{ |
68
|
2 |
|
if (!isset($this->resource['name'])) { |
69
|
|
|
$this->resource['name'] = (string) $this->resource['_id']; |
70
|
|
|
} |
71
|
|
|
|
72
|
2 |
|
return $this->resource; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
11 |
|
public function getData(): array |
79
|
|
|
{ |
80
|
11 |
|
if (!isset($this->resource['data'])) { |
81
|
|
|
return []; |
82
|
|
|
} |
83
|
|
|
|
84
|
11 |
|
return $this->resource['data']; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
2 |
|
public function getSecrets(): array |
91
|
|
|
{ |
92
|
2 |
|
if (!isset($this->resource['secrets'])) { |
93
|
2 |
|
return []; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $this->resource['secrets']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function getVersion(): int |
103
|
|
|
{ |
104
|
|
|
return $this->resource['version']; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function getChanged(): ?UTCDateTimeInterface |
111
|
|
|
{ |
112
|
|
|
return $this->resource['changed']; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function getCreated(): UTCDateTimeInterface |
119
|
|
|
{ |
120
|
|
|
return $this->resource['created']; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
|
|
public function getDeleted(): ?UTCDateTimeInterface |
127
|
|
|
{ |
128
|
|
|
return $this->resource['deleted']; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|