11<?php
22
3+ require_once (__DIR__ . '/TemplateEngineInterface.php ' );
4+
35/**
46 * TemplateEngine
57 *
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}
0 commit comments