|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see \Mailcode\Traits\Commands\Validation\TrackingIDTrait} trait. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Validation |
|
7
|
|
|
* @see \Mailcode\Traits\Commands\Validation\TrackingIDTrait |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode\Traits\Commands\Validation; |
|
13
|
|
|
|
|
14
|
|
|
use Mailcode\Commands\Command\ShowURL\AutoTrackingID; |
|
15
|
|
|
use Mailcode\Interfaces\Commands\Validation\TrackingIDInterface; |
|
16
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral; |
|
17
|
|
|
use Mailcode\Mailcode_Parser_Statement_Validator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Command validation drop-in: checks for the presence |
|
21
|
|
|
* of a tracking ID, which must be the first string |
|
22
|
|
|
* literal in the command's parameters list. If not |
|
23
|
|
|
* present or not a match for a tracking ID name, an |
|
24
|
|
|
* empty string is used as default. |
|
25
|
|
|
* |
|
26
|
|
|
* @package Mailcode |
|
27
|
|
|
* @subpackage Validation |
|
28
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
29
|
|
|
* |
|
30
|
|
|
* @see TrackingIDInterface |
|
31
|
|
|
* @property Mailcode_Parser_Statement_Validator $validator |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
trait TrackingIDTrait |
|
35
|
|
|
{ |
|
36
|
|
|
protected string $trackingID = ''; |
|
37
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral $trackingIDToken = null; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getTrackingID() : string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->trackingID ?? AutoTrackingID::generate($this); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function hasTrackingID() : bool |
|
48
|
|
|
{ |
|
49
|
|
|
return !empty($this->trackingID); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Checks if any of the parameters contain a trackingID. |
|
54
|
|
|
* This must be the first string literal in the parameters, |
|
55
|
|
|
* allowing any keywords to be placed before it, but not |
|
56
|
|
|
* after the optional query parameters. |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function validateSyntax_tracking_id() : void |
|
59
|
|
|
{ |
|
60
|
|
|
$literals = $this->requireParams() |
|
|
|
|
|
|
61
|
|
|
->getInfo() |
|
62
|
|
|
->getStringLiterals(); |
|
63
|
|
|
|
|
64
|
|
|
if(empty($literals)) |
|
65
|
|
|
{ |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$trackingID = array_shift($literals); |
|
70
|
|
|
|
|
71
|
|
|
$id = $trackingID->getText(); |
|
72
|
|
|
|
|
73
|
|
|
if(strpos($id, '=') === false) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->trackingID = $id; |
|
76
|
|
|
$this->trackingIDToken = $trackingID; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|