|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Mailcode |
|
4
|
|
|
* @subpackage Validation |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace Mailcode\Traits\Commands\Validation; |
|
10
|
|
|
|
|
11
|
|
|
use Mailcode\Interfaces\Commands\Validation\AbsoluteKeywordInterface; |
|
12
|
|
|
use Mailcode\Mailcode_Commands_Keywords; |
|
13
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Keyword; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Command validation drop-in: checks for the presence |
|
17
|
|
|
* of the `absolute:` keyword in the command statement, |
|
18
|
|
|
* and sets the absolute number flag accordingly. |
|
19
|
|
|
* |
|
20
|
|
|
* @package Mailcode |
|
21
|
|
|
* @subpackage Validation |
|
22
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
23
|
|
|
* |
|
24
|
|
|
* @see AbsoluteKeywordInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
trait AbsoluteKeywordTrait |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL |
|
30
|
|
|
*/ |
|
31
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword $absoluteKeyword = null; |
|
32
|
|
|
|
|
33
|
|
|
protected function validateSyntax_absolute(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$keywords = $this->requireParams() |
|
|
|
|
|
|
36
|
|
|
->getInfo() |
|
37
|
|
|
->getKeywords(); |
|
38
|
|
|
|
|
39
|
|
|
foreach ($keywords as $keyword) { |
|
40
|
|
|
if ($keyword->getKeyword() === Mailcode_Commands_Keywords::TYPE_ABSOLUTE) { |
|
41
|
|
|
$this->absoluteKeyword = $keyword; |
|
42
|
|
|
break; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function isAbsolute(): bool |
|
48
|
|
|
{ |
|
49
|
|
|
return isset($this->absoluteKeyword); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
* @return $this |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setAbsolute(bool $absolute): self |
|
57
|
|
|
{ |
|
58
|
|
|
if ($absolute === false && isset($this->absoluteKeyword)) { |
|
59
|
|
|
$this->requireParams()->getInfo()->removeKeyword($this->absoluteKeyword->getKeyword()); |
|
|
|
|
|
|
60
|
|
|
$this->absoluteKeyword = null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($absolute === true && !isset($this->absoluteKeyword)) { |
|
64
|
|
|
$this->requireParams() |
|
65
|
|
|
->getInfo() |
|
66
|
|
|
->addKeyword(Mailcode_Commands_Keywords::TYPE_ABSOLUTE); |
|
67
|
|
|
|
|
68
|
|
|
$this->validateSyntax_absolute(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|