Commit | Line | Data |
---|---|---|
3deba037 TO |
1 | <?php |
2 | ||
3 | class CRM_Core_CodeGen_Util_Smarty { | |
4 | /** | |
5 | * @var CRM_Core_CodeGen_Util_Smarty | |
6 | */ | |
7 | private static $singleton; | |
8 | ||
9 | /** | |
10 | * @return CRM_Core_CodeGen_Util_Smarty | |
11 | */ | |
12 | public static function singleton() { | |
13 | if (self::$singleton === NULL) { | |
14 | self::$singleton = new CRM_Core_CodeGen_Util_Smarty(); | |
15 | } | |
16 | return self::$singleton; | |
17 | } | |
18 | ||
19 | private $smartyPluginDirs = array(); | |
20 | ||
21 | /** | |
22 | * @var Smarty | |
23 | */ | |
24 | private $smarty; | |
25 | ||
26 | private $compileDir; | |
27 | ||
00be9182 | 28 | public function __destruct() { |
3deba037 TO |
29 | if ($this->compileDir) { |
30 | CRM_Core_CodeGen_Util_File::cleanTempDir($this->compileDir); | |
31 | } | |
32 | } | |
33 | ||
00be9182 | 34 | public function setPluginDirs($pluginDirs) { |
3deba037 TO |
35 | $this->smartyPluginDirs = $pluginDirs; |
36 | $this->smarty = NULL; | |
37 | } | |
38 | ||
00be9182 | 39 | public function getCompileDir() { |
3deba037 TO |
40 | if ($this->compileDir === NULL) { |
41 | $this->compileDir = CRM_Core_CodeGen_Util_File::createTempDir('templates_c_'); | |
42 | } | |
43 | return $this->compileDir; | |
44 | } | |
45 | ||
00be9182 | 46 | public function getSmarty() { |
3deba037 TO |
47 | if ($this->smarty === NULL) { |
48 | require_once 'Smarty/Smarty.class.php'; | |
49 | $this->smarty = new Smarty(); | |
50 | $this->smarty->template_dir = './templates'; | |
51 | $this->smarty->plugins_dir = $this->smartyPluginDirs; | |
52 | $this->smarty->compile_dir = $this->getCompileDir(); | |
53 | $this->smarty->clear_all_cache(); | |
54 | } | |
55 | return $this->smarty; | |
56 | } | |
57 | } |