1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Date_FormatInfo_Character} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Commands |
7
|
|
|
* @see Mailcode_Date_FormatInfo_Character |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Stores information on a single date format character |
16
|
|
|
* that can be used in the ShowDate command. |
17
|
|
|
* |
18
|
|
|
* @package Mailcode |
19
|
|
|
* @subpackage Commands |
20
|
|
|
* @author Sebastian Mordziol <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Mailcode_Date_FormatInfo_Character |
23
|
|
|
{ |
24
|
|
|
const ERROR_UNHANDLED_CHARTYPE = 55601; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $type; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $char; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $description; |
40
|
|
|
|
41
|
|
|
public function __construct(string $type, string $char, string $description) |
42
|
|
|
{ |
43
|
|
|
$this->type = $type; |
44
|
|
|
$this->char = $char; |
45
|
|
|
$this->description = $description; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Retrieves the format character (PHP date format). |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getChar() : string |
54
|
|
|
{ |
55
|
|
|
return $this->char; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Retrieves a human readable description of the character's role. |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getDescription() : string |
64
|
|
|
{ |
65
|
|
|
return $this->description; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Retrieves the character type ID. |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
* |
73
|
|
|
* @see Mailcode_Date_FormatInfo::CHARTYPE_DATE |
74
|
|
|
* @see Mailcode_Date_FormatInfo::CHARTYPE_TIME |
75
|
|
|
* @see Mailcode_Date_FormatInfo::CHARTYPE_PUNCTUATION |
76
|
|
|
*/ |
77
|
|
|
public function getTypeID() : string |
78
|
|
|
{ |
79
|
|
|
return $this->type; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Retrieves a human readable label for the character's type, e.g. "Date", "Time", "Punctuation". |
84
|
|
|
* |
85
|
|
|
* @throws Mailcode_Exception If the character type is unknown. |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getTypeLabel() : string |
89
|
|
|
{ |
90
|
|
|
switch($this->type) |
91
|
|
|
{ |
92
|
|
|
case Mailcode_Date_FormatInfo::CHARTYPE_DATE: |
93
|
|
|
return t('Date'); |
94
|
|
|
|
95
|
|
|
case Mailcode_Date_FormatInfo::CHARTYPE_TIME: |
96
|
|
|
return t('Time'); |
97
|
|
|
|
98
|
|
|
case Mailcode_Date_FormatInfo::CHARTYPE_PUNCTUATION: |
99
|
|
|
return t('Punctuation'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
throw new Mailcode_Exception( |
103
|
|
|
'Unhandled date character type', |
104
|
|
|
sprintf( |
105
|
|
|
'The date character type [%s] is not known.', |
106
|
|
|
$this->type |
107
|
|
|
), |
108
|
|
|
self::ERROR_UNHANDLED_CHARTYPE |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|