|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Parser_Statement_Tokenizer_Token} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Parser |
|
7
|
|
|
* @see Mailcode_Parser_Statement_Tokenizer_Token |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Abstract base class for a single token in a statement. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Mailcode |
|
18
|
|
|
* @subpackage Parser |
|
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class Mailcode_Parser_Statement_Tokenizer_Token implements Mailcode_Parser_Statement_Tokenizer_TypeInterface |
|
22
|
|
|
{ |
|
23
|
|
|
protected string $tokenID; |
|
24
|
|
|
protected ?Mailcode_Parser_Statement_Tokenizer_Token_ParamName $nameToken = null; |
|
25
|
|
|
protected string $matchedText; |
|
26
|
|
|
private ?Mailcode_Commands_Command $sourceCommand; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var mixed |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $subject; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $tokenID |
|
35
|
|
|
* @param string $matchedText |
|
36
|
|
|
* @param mixed $subject |
|
37
|
|
|
* @param Mailcode_Commands_Command|null $sourceCommand |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(string $tokenID, string $matchedText, $subject=null, ?Mailcode_Commands_Command $sourceCommand=null) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->tokenID = $tokenID; |
|
42
|
|
|
$this->matchedText = $matchedText; |
|
43
|
|
|
$this->subject = $subject; |
|
44
|
|
|
$this->sourceCommand = $sourceCommand; |
|
45
|
|
|
|
|
46
|
|
|
$this->init(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function init() : void |
|
50
|
|
|
{ |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Gets the name of the parameter, if specified. |
|
56
|
|
|
* Returns an empty string otherwise. |
|
57
|
|
|
* |
|
58
|
|
|
* NOTE: To set the name, use the command's statement |
|
59
|
|
|
* instead, and call the {@see Mailcode_Parser_Statement_Info::setParamName()} |
|
60
|
|
|
* method. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getName() : string |
|
65
|
|
|
{ |
|
66
|
|
|
if(isset($this->nameToken)) { |
|
67
|
|
|
return $this->nameToken->getParamName(); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return ''; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param Mailcode_Parser_Statement_Tokenizer_Token_ParamName $token |
|
75
|
|
|
* @return $this |
|
76
|
|
|
*/ |
|
77
|
|
|
public function registerNameToken(Mailcode_Parser_Statement_Tokenizer_Token_ParamName $token) : self |
|
78
|
|
|
{ |
|
79
|
|
|
$this->nameToken = $token; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
abstract public function hasSpacing() : bool; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return Mailcode_Commands_Command|null |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getSourceCommand(): ?Mailcode_Commands_Command |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->sourceCommand; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* The ID of the type. i.e. the class name ("Keyword", "StringLiteral"). |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getTypeID() : string |
|
98
|
|
|
{ |
|
99
|
|
|
$parts = explode('_', get_class($this)); |
|
100
|
|
|
return array_pop($parts); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Retrieves a unique ID of the token. |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getID() : string |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->tokenID; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function getMatchedText() : string |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->matchedText; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
abstract public function getNormalized() : string; |
|
118
|
|
|
|
|
119
|
|
|
final public function isValue() : bool |
|
120
|
|
|
{ |
|
121
|
|
|
return $this instanceof Mailcode_Parser_Statement_Tokenizer_ValueInterface; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.