|
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
|
|
|
/** Parses "string" and function(args) e.g. data(foo) or iteration(bar) */ |
|
9
|
|
|
class Last { |
|
10
|
|
|
private $baseData; |
|
|
|
|
|
|
11
|
|
|
private $autoLookup; |
|
12
|
|
|
/* |
|
13
|
|
|
Stores the last value e.g. |
|
14
|
|
|
"a" + "b" |
|
15
|
|
|
Will store "a" before reading the token for the + and perfoming the concatenate operation |
|
16
|
|
|
*/ |
|
17
|
|
|
private $last; |
|
18
|
|
|
private $data; |
|
19
|
|
|
private $result; |
|
20
|
|
|
private $traversing = false; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
public function __construct($data, $result, $autoLookup) { |
|
24
|
|
|
$this->data = $data; |
|
25
|
|
|
$this->result = $result; |
|
26
|
|
|
$this->autoLookup = $autoLookup; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function traverse() { |
|
31
|
|
|
if ($this->last !== null) $this->data->traverse($this->last); |
|
32
|
|
|
else { |
|
33
|
|
|
$lastResult = $this->result->pop(); |
|
|
|
|
|
|
34
|
|
|
if ($lastResult) { |
|
35
|
|
|
$this->data = new ValueData($lastResult); |
|
36
|
|
|
return $lastResult; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function clear() { |
|
42
|
|
|
$this->last = null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function isEmpty() { |
|
46
|
|
|
return $this->last == null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function processNested($parser, $token) { |
|
50
|
|
|
$funcResult = $this->data->parseNested($parser, $token, $this->last); |
|
51
|
|
|
$this->result->processValue($funcResult); |
|
|
|
|
|
|
52
|
|
|
$this->last = null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function read() { |
|
56
|
|
|
return $this->last; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function set($value) { |
|
60
|
|
|
$this->last = $value; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
//Applies the current operation to whatever is in $last based on $mode |
|
65
|
|
View Code Duplication |
public function process() { |
|
|
|
|
|
|
66
|
|
|
if ($this->last !== null) { |
|
67
|
|
|
try { |
|
68
|
|
|
$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing); |
|
69
|
|
|
$this->result->processValue($value); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
catch (\UnexpectedValueException $e) { |
|
72
|
|
|
$this->processLastUnexpected(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
private function processLastUnexpected() { |
|
|
|
|
|
|
78
|
|
|
if (!($this->autoLookup || $this->traversing)) { |
|
79
|
|
|
$this->result->processValue($this->last); |
|
80
|
|
|
} |
|
81
|
|
|
else { |
|
82
|
|
|
$this->result->clear(); |
|
83
|
|
|
$this->result[0] = false; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.