1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\FrontMatter; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ExpandedValue. |
12
|
|
|
* |
13
|
|
|
* An instance of this object is created to store the values and information related to the "value expansion" feature of |
14
|
|
|
* the FrontMatter parser |
15
|
|
|
*/ |
16
|
|
|
class ExpandedValue |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Store the original value with variables and this value will be updated in-place as it's evaluated. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $evaluated; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The definition of variable replacements that occurred for this specific string. |
27
|
|
|
* |
28
|
|
|
* The $key for the array would be the variable name without the % and the $value would be literal value that |
29
|
|
|
* replaced the variable in the string |
30
|
|
|
* |
31
|
|
|
* @var string[] |
32
|
|
|
*/ |
33
|
|
|
private $iterators; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* ExpandedValue constructor. |
37
|
|
|
* |
38
|
|
|
* @param string $string |
39
|
|
|
*/ |
40
|
8 |
|
public function __construct($string) |
41
|
|
|
{ |
42
|
8 |
|
$this->evaluated = $string; |
43
|
8 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
1 |
|
public function __toString() |
49
|
|
|
{ |
50
|
1 |
|
return $this->getEvaluated(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the current evaluated string. |
55
|
|
|
* |
56
|
|
|
* If the evaluation in FrontMatterParser hasn't been completed, this will return the partially evaluated string |
57
|
|
|
* variables still in place. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
8 |
|
public function getEvaluated() |
62
|
|
|
{ |
63
|
8 |
|
return $this->evaluated; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Update the currently evaluated string. |
68
|
|
|
* |
69
|
|
|
* As the string is being evaluated in the FrontMatterParser, this value will be updated as variables are iterated |
70
|
|
|
* through. |
71
|
|
|
* |
72
|
|
|
* @param string $string |
73
|
|
|
*/ |
74
|
7 |
|
public function setEvaluated($string) |
75
|
|
|
{ |
76
|
7 |
|
$this->evaluated = $string; |
77
|
7 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get all of the variable replacements that were used in this evaluated string. |
81
|
|
|
* |
82
|
|
|
* @return string[] |
83
|
|
|
*/ |
84
|
3 |
|
public function getIterators() |
85
|
|
|
{ |
86
|
3 |
|
return $this->iterators; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Record the value of a variable replacement. |
91
|
|
|
* |
92
|
|
|
* The variable name should NOT contain the % and the value should be as-is |
93
|
|
|
* |
94
|
|
|
* @param string $variableName |
95
|
|
|
* @param string|int $variableValue |
96
|
|
|
*/ |
97
|
7 |
|
public function setIterator($variableName, $variableValue) |
98
|
|
|
{ |
99
|
7 |
|
$this->iterators[$variableName] = $variableValue; |
100
|
7 |
|
} |
101
|
|
|
} |
102
|
|
|
|