Skip to content

Commit d87dad3

Browse files
committed
Merge branch 'dev'
2 parents 1ddd682 + e34147e commit d87dad3

8 files changed

Lines changed: 175 additions & 153 deletions

TemplateEngine.php

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
require_once(__DIR__ . '/TemplateEngineInterface.php');
4+
35
/**
46
* TemplateEngine
57
*
@@ -9,25 +11,25 @@
911
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License, version 2
1012
*
1113
*/
12-
abstract class TemplateEngine extends Wire
14+
abstract class TemplateEngine extends Wire implements TemplateEngineInterface
1315
{
1416

1517
/**
16-
* Stores module configuration per implemented TemplateEngine
18+
* Stores module configuration per implemented TemplateEngine.
1719
*
1820
* @var array
1921
*/
20-
protected static $loaded_config = array();
22+
protected static $loadedConfig = array();
2123

2224
/**
23-
* Filename of template file
25+
* Filename of template file.
2426
*
2527
* @var string
2628
*/
2729
protected $filename = '';
2830

2931
/**
30-
* Instance to the TemplateEngineFactory module
32+
* Instance of the TemplateEngineFactory module.
3133
*
3234
* @var TemplateEngineFactory
3335
*/
@@ -69,12 +71,8 @@ public function init()
6971

7072

7173
/**
72-
* Init engine, derived classes must use this method to setup the engine
73-
*/
74-
abstract public function initEngine();
75-
76-
77-
/**
74+
* Magic setter to pass variables to the template engine.
75+
*
7876
* @param $key
7977
* @param $value
8078
*/
@@ -84,17 +82,9 @@ public function __set($key, $value)
8482
}
8583

8684

87-
/**
88-
* Set a key/value pair to the template engine
89-
*
90-
* @param $key
91-
* @param $value
92-
*/
93-
abstract public function set($key, $value);
94-
9585

9686
/**
97-
* Alias for setArray
87+
* Alias for setArray.
9888
*
9989
* @param array $data
10090
*/
@@ -105,7 +95,7 @@ public function setMultiple($data = array())
10595

10696

10797
/**
108-
* Set multiple key/value pairs to the template engine
98+
* Set multiple key/value pairs to the template engine.
10999
*
110100
* @param array $data
111101
*/
@@ -118,14 +108,9 @@ public function setArray($data = array())
118108

119109

120110
/**
121-
* Render markup from template engine
111+
* Return the default configuration for all template engines. Derived classes should
112+
* overwrite this method and provide their own configuration options.
122113
*
123-
* @return mixed
124-
*/
125-
abstract public function render();
126-
127-
128-
/**
129114
* @return array
130115
*/
131116
public static function getDefaultConfig()
@@ -139,8 +124,8 @@ public static function getDefaultConfig()
139124

140125

141126
/**
142-
* ProcessWire does call this method and set config values from database
143-
* In our context, the config is loaded and available already in the constructor so just leave empty
127+
* ProcessWire does call this method and set config values from database.
128+
* In our context, the config is loaded and available already in the constructor so just leave empty.
144129
*
145130
* @param array $data
146131
*/
@@ -150,7 +135,7 @@ public function setConfigData(array $data = array())
150135

151136

152137
/**
153-
* Return config all implemented engines share in common
138+
* Return config all implemented engines share in common.
154139
*
155140
* @param array $data
156141
* @return InputfieldWrapper
@@ -188,26 +173,26 @@ public static function getModuleConfigInputfields(array $data)
188173

189174

190175
/**
191-
* Get a config value
176+
* Get a config value.
192177
*
193178
* @param $key
194179
* @return string|null
195180
*/
196181
public function getConfig($key)
197182
{
198-
return (isset(self::$loaded_config[$this->className][$key])) ? self::$loaded_config[$this->className][$key] : null;
183+
return (isset(self::$loadedConfig[$this->className][$key])) ? self::$loadedConfig[$this->className][$key] : null;
199184
}
200185

201186

202187
/**
203-
* Set a config value (runtime only and for all instances of the derived TemplateEngine class)
188+
* Set a config value (runtime only and for all instances of the derived TemplateEngine class).
204189
*
205190
* @param $key
206191
* @param $value
207192
*/
208193
public function setConfig($key, $value)
209194
{
210-
self::$loaded_config[$this->className][$key] = $value;
195+
self::$loadedConfig[$this->className][$key] = $value;
211196
}
212197

213198

@@ -235,7 +220,7 @@ public function setFilename($filename)
235220

236221

237222
/**
238-
* Get the path where templates are stored
223+
* Get the path where templates are stored.
239224
*
240225
* @return string
241226
*/
@@ -248,14 +233,14 @@ public function getTemplatesPath()
248233

249234

250235
/**
251-
* Load configuration once for all instances of TemplateEngine
236+
* Load configuration once for all instances of TemplateEngine.
252237
*
253238
*/
254239
protected function initConfig()
255240
{
256-
if (!isset(self::$loaded_config[$this->className])) {
241+
if (!isset(self::$loadedConfig[$this->className])) {
257242
$configs = $this->wire('modules')->getModuleConfigData($this);
258-
self::$loaded_config[$this->className] = array_merge($this->getDefaultConfig(), $configs);
243+
self::$loadedConfig[$this->className] = array_merge($this->getDefaultConfig(), $configs);
259244
}
260245
}
261246
}

TemplateEngineCache.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,35 @@
1010
* @author Stefan Wanzenried <stefan.wanzenried@gmail.com>
1111
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License, version 2
1212
*/
13-
1413
interface TemplateEngineCache {
1514

1615
/**
17-
* Get cached output of template or null if no cache exists
18-
*
16+
* Get cached output of template or null if no cache exists.
1917
* @return string|null
2018
*/
2119
public function getCache();
2220

2321

2422
/**
25-
* Cache output of current template
26-
*
23+
* Cache output of current template.
2724
*/
2825
public function storeCache();
2926

3027

3128
/**
32-
* Clear cache of current template
33-
*
29+
* Clear cache of current template.
3430
*/
3531
public function clearCache();
3632

3733

3834
/**
39-
* Clear cache completely, also cache of all other templates
40-
*
35+
* Clear cache completely, also cache of all other templates.
4136
*/
4237
public function clearAllCache();
4338

4439

4540
/**
46-
* Returns true if a cache exists for the template
47-
*
41+
* Returns true if a cache exists for the template.
4842
* @return bool
4943
*/
5044
public function isCached();

TemplateEngineChunk.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,31 @@ class TemplateEngineChunk extends WireData
2828
/**
2929
* @var string
3030
*/
31-
protected $chunk_file;
31+
protected $chunkFile;
3232

3333
/**
3434
* @var
3535
*/
36-
protected $template_file;
36+
protected $templateFile;
3737

3838

3939
/**
40-
* @param string $chunk_file Path to the chunk file to load, relative to site/templates/ without suffix
41-
* @param string $template_file Path to the corresponding template file (view) relative to the path where the engine stores its templates
40+
* @param string $chunkFile Path to the chunk file to load, relative to site/templates/ without suffix
41+
* @param string $templateFile Path to the corresponding template file (view) relative to the path where the engine stores its templates
4242
* @throws WireException
4343
*/
44-
public function __construct($chunk_file, $template_file = '')
44+
public function __construct($chunkFile, $templateFile = '')
4545
{
46-
$this->setChunkFile($chunk_file);
47-
$this->setTemplateFile($template_file);
46+
$this->setChunkFile($chunkFile);
47+
$this->setTemplateFile($templateFile);
4848
}
4949

5050

5151
/**
52-
* Set a value
53-
*
5452
* @param string $key
5553
* @param mixed $value
54+
* @throws WireException
5655
* @return $this
57-
*
5856
*/
5957
public function set($key, $value)
6058
{
@@ -95,33 +93,33 @@ public function render()
9593

9694

9795
/**
98-
* @param string $chunk_file The chunk file to load, relative to site/templates/ without suffix
96+
* @param string $chunkFile The chunk file to load, relative to site/templates/ without suffix
9997
* @throws WireException
10098
* @return $this
10199
*/
102-
public function setChunkFile($chunk_file)
100+
public function setChunkFile($chunkFile)
103101
{
104-
if (!is_file($this->getChunkPath($chunk_file))) {
105-
throw new WireException("Chunk file does not exist: '{$chunk_file}'");
102+
if (!is_file($this->getChunkPath($chunkFile))) {
103+
throw new WireException("Chunk file does not exist: '{$chunkFile}'");
106104
}
107-
$this->chunk_file = $chunk_file;
105+
$this->chunkFile = $chunkFile;
108106

109107
return $this;
110108
}
111109

112110

113111
/**
114-
* @param string $template_file The template file (view) that should be used to render this chunk
112+
* @param string $templateFile The template file (view) that should be used to render this chunk
115113
* @throws WireException
116114
* @return $this
117115
*/
118-
public function setTemplateFile($template_file)
116+
public function setTemplateFile($templateFile)
119117
{
120-
$template_file = ($template_file) ? $template_file : $this->chunk_file;
121-
$this->template_file = $template_file;
122-
$this->view = $this->wire('factory')->load($template_file);
118+
$templateFile = ($templateFile) ? $templateFile : $this->chunkFile;
119+
$this->templateFile = $templateFile;
120+
$this->view = $this->wire('factory')->load($templateFile);
123121
if ($this->view === null) {
124-
throw new WireException("View for chunk {$this->chunk_file} does not exist");
122+
throw new WireException("View for chunk {$this->chunkFile} does not exist");
125123
}
126124

127125
return $this;
@@ -135,20 +133,20 @@ public function setTemplateFile($template_file)
135133
*/
136134
protected function ___getChunk()
137135
{
138-
$chunk = new TemplateFile($this->getChunkPath($this->chunk_file));
136+
$chunk = new TemplateFile($this->getChunkPath($this->chunkFile));
139137
$chunk->setArray($this->getArray());
140138

141139
return $chunk;
142140
}
143141

144142

145143
/**
146-
* @param string $chunk_file
144+
* @param string $chunkFile
147145
* @return string
148146
*/
149-
protected function getChunkPath($chunk_file)
147+
protected function getChunkPath($chunkFile)
150148
{
151-
return $this->wire('config')->paths->templates . $chunk_file . '.' . $this->wire('config')->templateExtension;
149+
return $this->wire('config')->paths->templates . $chunkFile . '.' . $this->wire('config')->templateExtension;
152150
}
153151

154152
}

0 commit comments

Comments
 (0)