1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* It's free open-source software released under the MIT License. |
5
|
|
|
* |
6
|
|
|
* @author Anatoly Fenric <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Fenric |
8
|
|
|
* @license https://github.com/sunrise-php/http-header-kit/blob/master/LICENSE |
9
|
|
|
* @link https://github.com/sunrise-php/http-header-kit |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sunrise\Http\Header; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* HeaderSunset |
16
|
|
|
* |
17
|
|
|
* @link https://tools.ietf.org/id/draft-wilde-sunset-header-03.html |
18
|
|
|
* @link https://github.com/sunrise-php/http-header-kit/issues/1#issuecomment-457043527 |
19
|
|
|
*/ |
20
|
|
|
class HeaderSunset extends AbstractHeader implements HeaderInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Timestamp for the header field-value |
25
|
|
|
* |
26
|
|
|
* @var \DateTimeInterface |
27
|
|
|
*/ |
28
|
|
|
protected $timestamp; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor of the class |
32
|
|
|
* |
33
|
|
|
* @param \DateTimeInterface $timestamp |
34
|
|
|
*/ |
35
|
8 |
|
public function __construct(\DateTimeInterface $timestamp) |
36
|
|
|
{ |
37
|
8 |
|
$this->setTimestamp($timestamp); |
38
|
8 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Sets timestamp for the header field-value |
42
|
|
|
* |
43
|
|
|
* @param \DateTimeInterface $timestamp |
44
|
|
|
* |
45
|
|
|
* @return self |
46
|
|
|
*/ |
47
|
8 |
|
public function setTimestamp(\DateTimeInterface $timestamp) : self |
48
|
|
|
{ |
49
|
8 |
|
$this->timestamp = $timestamp; |
50
|
|
|
|
51
|
8 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets timestamp for the header field-value |
56
|
|
|
* |
57
|
|
|
* @return \DateTimeInterface |
58
|
|
|
*/ |
59
|
6 |
|
public function getTimestamp() : \DateTimeInterface |
60
|
|
|
{ |
61
|
6 |
|
return $this->timestamp; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
4 |
|
public function getFieldName() : string |
68
|
|
|
{ |
69
|
4 |
|
return 'Sunset'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
*/ |
75
|
4 |
|
public function getFieldValue() : string |
76
|
|
|
{ |
77
|
4 |
|
$this->getTimestamp()->setTimezone(new \DateTimeZone('GMT')); |
78
|
|
|
|
79
|
4 |
|
return $this->getTimestamp()->format(\DateTime::RFC822); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|