1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see \Mailcode\Traits\Commands\Validation\BreakAtTrait} trait. |
4
|
|
|
* |
5
|
|
|
* @see \Mailcode\Traits\Commands\Validation\BreakAtTrait |
6
|
|
|
* @subpackage Validation |
7
|
|
|
* @package Mailcode |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode\Traits\Commands\Validation; |
13
|
|
|
|
14
|
|
|
use Mailcode\Interfaces\Commands\Validation\BreakAtInterface; |
15
|
|
|
use Mailcode\Mailcode_Commands_Keywords; |
16
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token; |
17
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Number; |
18
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Variable; |
19
|
|
|
use function Mailcode\t; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Command validation drop-in: checks for the presence |
23
|
|
|
* of the `break-at:` keyword in the command statement. |
24
|
|
|
* |
25
|
|
|
* @package Mailcode |
26
|
|
|
* @subpackage Validation |
27
|
|
|
* @author Olaf Böcker <[email protected]> |
28
|
|
|
* |
29
|
|
|
* @see BreakAtInterface |
30
|
|
|
*/ |
31
|
|
|
trait BreakAtTrait |
32
|
|
|
{ |
33
|
|
|
private bool $breakAtEnabled = false; |
34
|
|
|
|
35
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token $breakAtToken = null; |
36
|
|
|
|
37
|
|
|
protected function validateSyntax_check_break_at(): void |
38
|
|
|
{ |
39
|
|
|
$this->breakAtToken = $this->requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_BREAK_AT); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_BREAK_AT); |
42
|
|
|
|
43
|
|
|
$this->breakAtEnabled = $val->isValid() && $this->breakAtToken != null;; |
44
|
|
|
|
45
|
|
|
if ($this->breakAtEnabled) { |
46
|
|
|
if (!$this->breakAtToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number && |
47
|
|
|
!$this->breakAtToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) { |
48
|
|
|
$this->validationResult->makeError( |
49
|
|
|
t('Invalid break-at type.' . ' ' . 'Expected Number or Variable.'), |
50
|
|
|
BreakAtInterface::VALIDATION_BREAK_AT_CODE_WRONG_TYPE |
51
|
|
|
); |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isBreakAtEnabled(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->breakAtEnabled; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getBreakAtToken(): ?Mailcode_Parser_Statement_Tokenizer_Token |
63
|
|
|
{ |
64
|
|
|
return $this->breakAtToken; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|