|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Mailcode; |
|
6
|
|
|
|
|
7
|
|
|
use AppUtils\OperationResult; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Command validation drop-in: used by commands that accept |
|
11
|
|
|
* a single list variable property. Ensures that the specified |
|
12
|
|
|
* variable uses the scheme `$LIST.PROPERTY`, and not a single |
|
13
|
|
|
* path variable like `$FOO`. |
|
14
|
|
|
* |
|
15
|
|
|
* @package Mailcode |
|
16
|
|
|
* @subpackage Validation |
|
17
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
18
|
|
|
* |
|
19
|
|
|
* @property Mailcode_Parser_Statement_Validator $validator |
|
20
|
|
|
* @property OperationResult $validationResult |
|
21
|
|
|
* |
|
22
|
|
|
* @see Mailcode_Interfaces_Commands_ListPropertyVariable |
|
23
|
|
|
*/ |
|
24
|
|
|
trait Mailcode_Traits_Commands_Validation_ListPropertyVariable |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Mailcode_Variables_Variable|null |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $listVariable = null; |
|
30
|
|
|
|
|
31
|
|
|
abstract public function getVariable() : Mailcode_Variables_Variable; |
|
32
|
|
|
|
|
33
|
|
|
protected function validateSyntax_list_property_variable() : void |
|
34
|
|
|
{ |
|
35
|
|
|
$var = $this->getVariable(); |
|
36
|
|
|
|
|
37
|
|
|
// Split the variable name by the dot |
|
38
|
|
|
$parts = explode('.', ltrim($var->getFullName(), '$')); |
|
39
|
|
|
|
|
40
|
|
|
if(count($parts) !== 2) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->validationResult->makeError( |
|
43
|
|
|
t('The variable %1$s is not a list property:', '<code>'.$var->getFullName().'</code>').' '. |
|
44
|
|
|
t('Expected a name with a dot, like %1$s', '<code>$'.t('LIST.PROPERTY').'</code>'), |
|
45
|
|
|
Mailcode_Interfaces_Commands_ListPropertyVariable::VALIDATION_NOT_A_LIST_PROPERTY |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// Create the list variable from the path of the property variable. |
|
52
|
|
|
$this->listVariable = new Mailcode_Variables_Variable( |
|
53
|
|
|
'', |
|
54
|
|
|
$parts[0], |
|
55
|
|
|
'$'.$parts[0], |
|
56
|
|
|
$var->getSourceCommand() |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Retrieves the specified list variable, if any. |
|
62
|
|
|
* If the command is erroneous no list variable may |
|
63
|
|
|
* be present, in which case an exception is thrown. |
|
64
|
|
|
* |
|
65
|
|
|
* @return Mailcode_Variables_Variable |
|
66
|
|
|
* @throws Mailcode_Exception |
|
67
|
|
|
* |
|
68
|
|
|
* @see Mailcode_Interfaces_Commands_ListPropertyVariable::ERROR_NO_LIST_VARIABLE_PRESENT |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getListVariable() : Mailcode_Variables_Variable |
|
71
|
|
|
{ |
|
72
|
|
|
if(isset($this->listVariable)) |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->listVariable; |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
throw new Mailcode_Exception( |
|
78
|
|
|
'No list variable present.', |
|
79
|
|
|
'', |
|
80
|
|
|
Mailcode_Interfaces_Commands_ListPropertyVariable::ERROR_NO_LIST_VARIABLE_PRESENT |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return Mailcode_Variables_Variable |
|
86
|
|
|
* @throws Mailcode_Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getListProperty() : Mailcode_Variables_Variable |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->getVariable(); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|