|
@@ -40,7 +40,9 @@ discard block |
|
|
block discarded – undo |
|
40
|
40
|
|
|
41
|
41
|
//Allow $time to be set via arguments to spoof time passage during tests |
|
42
|
42
|
foreach ($this->getRules($template) as $rule) { |
|
43
|
|
- if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data); |
|
|
43
|
+ if ($rule->shouldRun($this->time)) { |
|
|
44
|
+ $this->executeTssRule($rule, $template, $data); |
|
|
45
|
+ } |
|
44
|
46
|
} |
|
45
|
47
|
|
|
46
|
48
|
$result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)]; |
|
@@ -57,7 +59,9 @@ discard block |
|
|
block discarded – undo |
|
57
|
59
|
$formatter->register(new Formatter\Date($locale)); |
|
58
|
60
|
$formatter->register(new Formatter\StringFormatter()); |
|
59
|
61
|
|
|
60
|
|
- foreach ($this->formatters as $format) $formatter->register($format); |
|
|
62
|
+ foreach ($this->formatters as $format) { |
|
|
63
|
+ $formatter->register($format); |
|
|
64
|
+ } |
|
61
|
65
|
|
|
62
|
66
|
$this->registerProperty('content', new Property\Content($data, $headers, $formatter)); |
|
63
|
67
|
$this->registerProperty('repeat', new Property\Repeat($data)); |
|
@@ -75,7 +79,9 @@ discard block |
|
|
block discarded – undo |
|
75
|
79
|
private function executeTssRule($rule, $template, $data) { |
|
76
|
80
|
$rule->touch(); |
|
77
|
81
|
$hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data); |
|
78
|
|
- foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property); |
|
|
82
|
+ foreach ($this->registeredProperties as $name => $property) { |
|
|
83
|
+ $hook->registerProperty($name, $property); |
|
|
84
|
+ } |
|
79
|
85
|
$template->addHook($rule->query, $hook); |
|
80
|
86
|
} |
|
81
|
87
|
|
|
@@ -84,8 +90,9 @@ discard block |
|
|
block discarded – undo |
|
84
|
90
|
if (trim($this->template)[0] !== '<') { |
|
85
|
91
|
$xml = $this->cache->load($this->template, filemtime($this->template)); |
|
86
|
92
|
return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
|
|
93
|
+ } else { |
|
|
94
|
+ return ['body' => $this->template, 'headers' => []]; |
|
87
|
95
|
} |
|
88
|
|
- else return ['body' => $this->template, 'headers' => []]; |
|
89
|
96
|
} |
|
90
|
97
|
|
|
91
|
98
|
//Load the TSS rules either from a file or as a string |
|
@@ -99,10 +106,14 @@ discard block |
|
|
block discarded – undo |
|
99
|
106
|
$key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
100
|
107
|
//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
|
101
|
108
|
$rules = $this->cache->load($key, filemtime($this->tss)); |
|
102
|
|
- if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
103
|
|
- else return $rules; |
|
|
109
|
+ if (!$rules) { |
|
|
110
|
+ return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
|
111
|
+ } else { |
|
|
112
|
+ return $rules; |
|
|
113
|
+ } |
|
|
114
|
+ } else { |
|
|
115
|
+ return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
104
|
116
|
} |
|
105
|
|
- else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
106
|
117
|
} |
|
107
|
118
|
|
|
108
|
119
|
public function setCache(\ArrayAccess $cache) { |
|
@@ -110,9 +121,13 @@ discard block |
|
|
block discarded – undo |
|
110
|
121
|
} |
|
111
|
122
|
|
|
112
|
123
|
private function getLocale() { |
|
113
|
|
- if (is_array($this->locale)) return $this->locale; |
|
114
|
|
- else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
115
|
|
- else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
|
124
|
+ if (is_array($this->locale)) { |
|
|
125
|
+ return $this->locale; |
|
|
126
|
+ } else if (strlen($this->locale) > 0) { |
|
|
127
|
+ return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
|
128
|
+ } else { |
|
|
129
|
+ return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
|
130
|
+ } |
|
116
|
131
|
} |
|
117
|
132
|
|
|
118
|
133
|
public function registerProperty($name, Property $property) { |