|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Commands_Command} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Commands |
|
7
|
|
|
* @see Mailcode_Commands_Command |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Validation helper for a command's parameters statement. |
|
16
|
|
|
* It is the counterpart to the tokenizer: The tokenizer |
|
17
|
|
|
* finds the tokens, and ensures the syntax is correct. The |
|
18
|
|
|
* validator then allows checking the correct tokens are |
|
19
|
|
|
* present for the command. |
|
20
|
|
|
* |
|
21
|
|
|
* Offers a range of methods that make it easy to check |
|
22
|
|
|
* whether expected parameters exist, enforcing a specific |
|
23
|
|
|
* order, or freeform. |
|
24
|
|
|
* |
|
25
|
|
|
* @package Mailcode |
|
26
|
|
|
* @subpackage Commands |
|
27
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class Mailcode_Parser_Statement_Validator |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var Mailcode_Parser_Statement |
|
33
|
|
|
*/ |
|
34
|
|
|
private $statement; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(Mailcode_Parser_Statement $statement) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->statement = $statement; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Creates a variable validator: checks whether a single |
|
43
|
|
|
* variable token is present in the parameters. |
|
44
|
|
|
* |
|
45
|
|
|
* @return Mailcode_Parser_Statement_Validator_Type_Variable |
|
46
|
|
|
*/ |
|
47
|
|
|
public function createVariable() : Mailcode_Parser_Statement_Validator_Type_Variable |
|
48
|
|
|
{ |
|
49
|
|
|
$validate = new Mailcode_Parser_Statement_Validator_Type_Variable($this->statement); |
|
50
|
|
|
|
|
51
|
|
|
return $validate; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Creates a keyword validator: checks whether a single |
|
56
|
|
|
* keyword token is present in the parameters. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $keywordName |
|
59
|
|
|
* @return Mailcode_Parser_Statement_Validator_Type_Keyword |
|
60
|
|
|
*/ |
|
61
|
|
|
public function createKeyword(string $keywordName) : Mailcode_Parser_Statement_Validator_Type_Keyword |
|
62
|
|
|
{ |
|
63
|
|
|
$validate = new Mailcode_Parser_Statement_Validator_Type_Keyword( |
|
64
|
|
|
$this->statement, |
|
65
|
|
|
$keywordName |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
return $validate; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function createStringLiteral() : Mailcode_Parser_Statement_Validator_Type_StringLiteral |
|
72
|
|
|
{ |
|
73
|
|
|
$validate = new Mailcode_Parser_Statement_Validator_Type_StringLiteral($this->statement); |
|
74
|
|
|
|
|
75
|
|
|
return $validate; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function createValue() : Mailcode_Parser_Statement_Validator_Type_Value |
|
79
|
|
|
{ |
|
80
|
|
|
$validate = new Mailcode_Parser_Statement_Validator_Type_Value($this->statement); |
|
81
|
|
|
|
|
82
|
|
|
return $validate; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function createOperand(string $sign='') : Mailcode_Parser_Statement_Validator_Type_Operand |
|
86
|
|
|
{ |
|
87
|
|
|
$validate = new Mailcode_Parser_Statement_Validator_Type_Operand($this->statement); |
|
88
|
|
|
|
|
89
|
|
|
if(!empty($sign)) |
|
90
|
|
|
{ |
|
91
|
|
|
$validate->setOperandSign($sign); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $validate; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|