1 | <?php |
||
17 | class Templater { |
||
18 | |||
19 | /** |
||
20 | * Template adapter, it would be twig or any php template lib. |
||
21 | * |
||
22 | * @var $adapter object Template Engine object |
||
23 | */ |
||
24 | private $adapter = []; |
||
25 | |||
26 | /** |
||
27 | * Template adapter, it would be twig or any php template lib. |
||
28 | * |
||
29 | * @var $adapter object Template Engine object |
||
30 | */ |
||
31 | private $dir_path; |
||
32 | |||
33 | /** |
||
34 | * Template adapter name, it would be twig or any php template lib. |
||
35 | * |
||
36 | * @var $adapter object Template Engine object |
||
37 | */ |
||
38 | private $adapter_name; |
||
39 | |||
40 | /** |
||
41 | * Initialize function |
||
42 | * - Load twig as default engine |
||
43 | * |
||
44 | * @var $dir_path string Path to template folder. |
||
45 | */ |
||
46 | public function __construct($dir_path, $adapter_name = 'blade') { |
||
51 | |||
52 | /** |
||
53 | * Load Twig as default adapter |
||
54 | * |
||
55 | * @return Twig_Environment |
||
56 | */ |
||
57 | public function loadTwig() { |
||
66 | |||
67 | /** |
||
68 | * Load Blade |
||
69 | * |
||
70 | * @return Blade |
||
71 | */ |
||
72 | public function loadBlade() { |
||
76 | |||
77 | /** |
||
78 | * Add custom functions for Twig |
||
79 | * |
||
80 | * @param string |
||
81 | * @param function |
||
82 | * |
||
83 | * @return Blade |
||
84 | */ |
||
85 | public function addFunction($functionName, $callback) { |
||
91 | |||
92 | /** |
||
93 | * Load adapter, currently we are using 2 adapters: twig and blade |
||
94 | * |
||
95 | * @var $adapter_name string Path to template folder. |
||
96 | * @return mixed |
||
97 | */ |
||
98 | public function loadAdapter($adapter_name) { |
||
109 | |||
110 | /** |
||
111 | * Alias for engine render function |
||
112 | * |
||
113 | * @var $template string Template file name (e.g. test.php, folder/test.phtml...) |
||
114 | * @var $data array Data array. E.g. ['list' => $list] |
||
115 | * |
||
116 | * @return string Rendered HTML/text |
||
117 | */ |
||
118 | public function render($template, $data = []) { |
||
128 | |||
129 | /** |
||
130 | * Setup Wordpress themes support. |
||
131 | * The template engine will find template file in theme folder before find it in plugin/application folder |
||
132 | * 1. /wp-content/themes/{theme-name}/templates/{application-name}/ |
||
133 | * 2. /path/to/application/ |
||
134 | * |
||
135 | * @var $app_name string Your application name, should be lowercase, letters only. |
||
136 | * |
||
137 | * @return object \VA\Templater\Engine |
||
138 | */ |
||
139 | public function setWordPressThemeSupport($app_name) { |
||
157 | |||
158 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.