|
1
|
|
|
<?php |
|
2
|
|
|
/* @description Transformation Style Sheets - Revolutionising PHP templating * |
|
3
|
|
|
* @author Tom Butler [email protected] * |
|
4
|
|
|
* @copyright 2015 Tom Butler <[email protected]> | https://r.je/ * |
|
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License * |
|
6
|
|
|
* @version 1.0 */ |
|
7
|
|
|
namespace Transphporm\Parser; |
|
8
|
|
|
class ValueResult implements \ArrayAccess { |
|
9
|
|
|
private $result = []; |
|
10
|
|
|
|
|
11
|
|
|
/* |
|
12
|
|
|
The next operation to perform. Will be one of the following: |
|
13
|
|
|
ARG - A new value e.g, "a","b" becomes ["a", "b"] |
|
14
|
|
|
CONCAT - Concat onto the current arg e.g "a" + "b" becomes ["ab"] |
|
15
|
|
|
NOT - Boolean operation "a" != "b" becomes [true] |
|
16
|
|
|
EQUALS - Boolean operation "a" = "b" becomes [false] |
|
17
|
|
|
*/ |
|
18
|
|
|
private $mode = Tokenizer::ARG; |
|
19
|
|
|
|
|
20
|
|
|
//Processes $newValue using $mode. Either concats to the current argument, adds a new argument |
|
21
|
|
|
//Or usess the two arguments for a boolean comparison |
|
22
|
|
|
public function processValue($newValue) { |
|
23
|
|
|
$funcs = [ |
|
24
|
|
|
Tokenizer::ARG => 'arg', |
|
25
|
|
|
Tokenizer::CONCAT => 'concat', |
|
26
|
|
|
Tokenizer::EQUALS => 'equals', |
|
27
|
|
|
Tokenizer::NOT => 'not' |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
$this->{$funcs[$this->mode]}($newValue); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function arg($value) { |
|
34
|
|
|
$this->result[] = $value; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function concat($value) { |
|
38
|
|
|
$this->result[count($this->result)-1] .= $value; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function not($value) { |
|
42
|
|
|
$this->result[count($this->result)-1] = $this->result[count($this->result)-1] != $value; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function equals($value) { |
|
46
|
|
|
$this->result[count($this->result)-1] = $this->result[count($this->result)-1] == $value; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function setMode($mode) { |
|
51
|
|
|
$this->mode = $mode; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getMode() { |
|
55
|
|
|
return $this->mode; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getResult() { |
|
59
|
|
|
return $this->result; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function pop() { |
|
63
|
|
|
return array_pop($this->result); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function offsetSet($key, $value) { |
|
67
|
|
|
$this->result[$key] = $value; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function offsetGet($key) { |
|
71
|
|
|
return $this->result[$key]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function offsetUnset($key) { |
|
75
|
|
|
unset($this->result[$key]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function offsetExists($key) { |
|
79
|
|
|
return isset($this->result[$key]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function clear() { |
|
83
|
|
|
$this->result = []; |
|
84
|
|
|
} |
|
85
|
|
|
} |