1
|
|
|
<?php |
2
|
|
|
namespace JayaCode\Framework\Core\View; |
3
|
|
|
|
4
|
|
|
use Mustache_Engine; |
5
|
|
|
use Mustache_Loader_FilesystemLoader; |
6
|
|
|
use Mustache_Logger_StreamLogger; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class View |
10
|
|
|
* @package JayaCode\Framework\Core\View |
11
|
|
|
*/ |
12
|
|
|
class View extends Mustache_Engine |
13
|
|
|
{ |
14
|
|
|
private $app_dir; |
15
|
|
|
private $view_dir; |
16
|
|
|
|
17
|
|
|
private $engineConfig; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* View constructor. |
21
|
|
|
* @param array $options |
22
|
|
|
*/ |
23
|
|
|
public function __construct(array $options = array()) |
24
|
|
|
{ |
25
|
|
|
$this->app_dir = defined("__APP_DIR__") ? __APP_DIR__ : '/'; |
26
|
|
|
$this->view_dir = defined("__APP_DIR__") ? __APP_DIR__.'/resource/views' : '/'; |
27
|
|
|
|
28
|
|
|
if (!empty($options)) { |
29
|
|
|
$this->engineConfig = $options; |
30
|
|
|
} else { |
31
|
|
|
$this->defaultEngineConfig(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
parent::__construct($this->engineConfig); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Init default view engine options |
39
|
|
|
*/ |
40
|
|
|
private function defaultEngineConfig() |
41
|
|
|
{ |
42
|
|
|
$this->engineConfig = array( |
43
|
|
|
'cache' => $this->app_dir .'/tmp/cache/mustache', |
44
|
|
|
'cache_file_mode' => 0666, // Please, configure your umask instead of doing this :) |
45
|
|
|
'cache_lambda_templates' => true, |
46
|
|
|
'loader' => new Mustache_Loader_FilesystemLoader($this->view_dir), |
47
|
|
|
'partials_loader' => new Mustache_Loader_FilesystemLoader($this->view_dir), |
48
|
|
|
'escape' => function ($value) { |
49
|
|
|
return htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); |
50
|
|
|
}, |
51
|
|
|
'charset' => 'ISO-8859-1', |
52
|
|
|
'logger' => new Mustache_Logger_StreamLogger('php://stderr'), |
53
|
|
|
'strict_callables' => true, |
54
|
|
|
'pragmas' => [Mustache_Engine::PRAGMA_FILTERS], |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|