|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Saikootau\ApiBundle\Resource; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use DateTimeInterface; |
|
9
|
|
|
use JMS\Serializer\Annotation as Serializer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @Serializer\XmlRoot(name="service") |
|
13
|
|
|
*/ |
|
14
|
|
|
class Service |
|
15
|
|
|
{ |
|
16
|
|
|
public const DEFAULT_VERSION = '1.0'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @Serializer\XmlAttribute |
|
20
|
|
|
* @Serializer\Type("string") |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $version = self::DEFAULT_VERSION; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @Serializer\XmlAttribute |
|
28
|
|
|
* @Serializer\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") |
|
29
|
|
|
* |
|
30
|
|
|
* @var DateTimeInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $timestamp; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @Serializer\Type("Saikootau\ApiBundle\Resource\Request") |
|
36
|
|
|
* |
|
37
|
|
|
* @var Request |
|
38
|
|
|
*/ |
|
39
|
|
|
private $request; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @Serializer\XmlList( |
|
43
|
|
|
* inline=true, |
|
44
|
|
|
* entry="error" |
|
45
|
|
|
* ) |
|
46
|
|
|
* @Serializer\SerializedName("errors") |
|
47
|
|
|
* @Serializer\Type("array<Saikootau\ApiBundle\Resource\Error>") |
|
48
|
|
|
* |
|
49
|
|
|
* @var Error[] |
|
50
|
|
|
*/ |
|
51
|
|
|
private $errors; |
|
52
|
|
|
|
|
53
|
13 |
|
public function __construct(Request $request, Error ...$errors) |
|
54
|
|
|
{ |
|
55
|
13 |
|
$this->errors = $errors; |
|
56
|
13 |
|
$this->request = $request; |
|
57
|
13 |
|
$this->timestamp = new DateTimeImmutable(); |
|
58
|
13 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the api version of this response. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function getVersion(): string |
|
66
|
|
|
{ |
|
67
|
3 |
|
return $this->version; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Set the api version for this response. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $version |
|
74
|
|
|
* |
|
75
|
|
|
* @return Service |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function setVersion(string $version): self |
|
78
|
|
|
{ |
|
79
|
1 |
|
$this->version = $version; |
|
80
|
|
|
|
|
81
|
1 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Returns the timestamp this response was created at. |
|
86
|
|
|
* |
|
87
|
|
|
* @return DateTimeInterface |
|
88
|
|
|
*/ |
|
89
|
2 |
|
public function getTimestamp(): DateTimeInterface |
|
90
|
|
|
{ |
|
91
|
2 |
|
return $this->timestamp; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the request associated with this response. |
|
96
|
|
|
* |
|
97
|
|
|
* @return Request |
|
98
|
|
|
*/ |
|
99
|
3 |
|
public function getRequest(): Request |
|
100
|
|
|
{ |
|
101
|
3 |
|
return $this->request; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Returns a list of errors associated with this response. |
|
106
|
|
|
* |
|
107
|
|
|
* @return Error[] |
|
108
|
|
|
*/ |
|
109
|
4 |
|
public function getErrors(): array |
|
110
|
|
|
{ |
|
111
|
4 |
|
return $this->errors; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|