|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the trait {@see \Mailcode\Traits\Commands\Validation\TimezoneTrait}. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Validation |
|
7
|
|
|
* @see \Mailcode\Traits\Commands\Validation\TimezoneTrait |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode\Traits\Commands\Validation; |
|
13
|
|
|
|
|
14
|
|
|
use Mailcode\Interfaces\Commands\Validation\TimezoneInterface; |
|
15
|
|
|
use Mailcode\Mailcode_Commands_Keywords; |
|
16
|
|
|
use Mailcode\Mailcode; |
|
17
|
|
|
use Mailcode\Mailcode_Commands_Command_ShowDate; |
|
18
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token; |
|
19
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral; |
|
20
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Variable; |
|
21
|
|
|
use Mailcode\Mailcode_Variables_Variable; |
|
22
|
|
|
use function Mailcode\t; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @package Mailcode |
|
26
|
|
|
* @subpackage Validation |
|
27
|
|
|
* @author Olaf Böcker <[email protected]> |
|
28
|
|
|
* |
|
29
|
|
|
* @see TimezoneInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
trait TimezoneTrait |
|
32
|
|
|
{ |
|
33
|
|
|
private bool $timezoneEnabled = false; |
|
34
|
|
|
|
|
35
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token $timezoneToken = null; |
|
36
|
|
|
|
|
37
|
|
|
protected function validateSyntax_check_timezone(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->timezoneToken = $this->requireParams() |
|
|
|
|
|
|
40
|
|
|
->getInfo() |
|
41
|
|
|
->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_TIMEZONE); |
|
42
|
|
|
|
|
43
|
|
|
$val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_TIMEZONE); |
|
44
|
|
|
|
|
45
|
|
|
if ($this->timezoneToken === null || !$val->isValid()) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (!$this->timezoneToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral && |
|
50
|
|
|
!$this->timezoneToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) { |
|
51
|
|
|
$this->validationResult->makeError( |
|
52
|
|
|
t('Invalid timezone:') . ' ' . t('Expected a string or variable.'), |
|
53
|
|
|
TimezoneInterface::VALIDATION_TIMEZONE_CODE_WRONG_TYPE |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Gets the time zone to use for the command. If none has |
|
60
|
|
|
* been specified in the original command, the default |
|
61
|
|
|
* time zone is used as defined via {@see Mailcode_Commands_Command_ShowDate::setDefaultTimezone()}. |
|
62
|
|
|
* |
|
63
|
|
|
* @return Mailcode_Parser_Statement_Tokenizer_Token |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getTimezoneToken(): Mailcode_Parser_Statement_Tokenizer_Token |
|
66
|
|
|
{ |
|
67
|
|
|
if(!isset($this->timezoneToken)) { |
|
68
|
|
|
$this->timezoneToken = $this->createTimeZoneToken(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this->timezoneToken; |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Creates the default time zone token on demand. |
|
76
|
|
|
* |
|
77
|
|
|
* @return Mailcode_Parser_Statement_Tokenizer_Token |
|
78
|
|
|
*/ |
|
79
|
|
|
private function createTimeZoneToken() : Mailcode_Parser_Statement_Tokenizer_Token |
|
80
|
|
|
{ |
|
81
|
|
|
$default = Mailcode_Commands_Command_ShowDate::getDefaultTimezone(); |
|
82
|
|
|
|
|
83
|
|
|
if($default instanceof Mailcode_Variables_Variable) { |
|
84
|
|
|
return new Mailcode_Parser_Statement_Tokenizer_Token_Variable( |
|
85
|
|
|
'showdate-timezone-token', |
|
86
|
|
|
$default->getFullName(), |
|
87
|
|
|
$default, |
|
88
|
|
|
$this |
|
|
|
|
|
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return new Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral( |
|
93
|
|
|
'showdate-timezone-token', |
|
94
|
|
|
$default, |
|
95
|
|
|
null, |
|
96
|
|
|
$this |
|
|
|
|
|
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|