This repository was archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEngine.php
79 lines (69 loc) · 1.51 KB
/
Engine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* SimpleTemplate - PHP template engine
*
* @link https://github.com/FreeWall/SimpleTemplate
* @author Michal Vaněk
*/
namespace SimpleTemplate;
/** Include other files */
require_once __DIR__."/Cache.php";
require_once __DIR__."/Parser.php";
require_once __DIR__."/Filters.php";
require_once __DIR__."/Validate.php";
require_once __DIR__."/Exception.php";
class Engine {
/** @var Parser */
private $parser;
/**
* Construct method.
* @param array
*/
public function __construct($params){
global $lang;
Cache::clearCacheFolder();
$this->parser = new Parser();
$this->parser->setParams(array("global" => \Eshop::getGlobalVariables(),"lang" => $lang)+$params);
}
/**
* Cache settings.
* @param boolean
*/
public function setCache($bool){
Cache::setEnabled($bool);
}
/**
* Load template from file.
* @param string file name
*/
public function loadTemplate($name){
if(file_exists($name)){
$content = file_get_contents($name);
$this->parser->setContent($content);
}
else throw new Exception("File '$name' not found.");
}
/**
* Load template from string.
* @param string
*/
public function loadTemplateContent($content){
$this->parser->setContent($content);
}
/**
* Add custom filter
* @param string
* @param callback
*/
public function addFilter($s,$callback){
Filters::addFilter($s,$callback);
}
/**
* Returns parsed template.
* @return string
*/
public function getOutput(){
$this->parser->parse();
return $this->parser->getOutput();
}
}