|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Koch Framework |
|
5
|
|
|
* Jens-André Koch © 2005 - onwards. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of "Koch Framework". |
|
8
|
|
|
* |
|
9
|
|
|
* License: GNU/GPL v2 or any later version, see LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Koch\View\Renderer; |
|
26
|
|
|
|
|
27
|
|
|
use Koch\View\AbstractRenderer; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Koch Framework - View Renderer for Xtemplate templates. |
|
31
|
|
|
* |
|
32
|
|
|
* This is a wrapper/adapter for rendering with XTemplate. |
|
33
|
|
|
* |
|
34
|
|
|
* @link http://www.phpxtemplate.org/ Offical Website of PHP XTemplate |
|
35
|
|
|
* @link http://xtpl.sourceforge.net/ Project's Website at Sourceforge |
|
36
|
|
|
*/ |
|
37
|
|
|
class Xtemplate extends AbstractRenderer |
|
38
|
|
|
{ |
|
39
|
|
|
/* @var \XTemplate */ |
|
40
|
|
|
public $renderer = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param array $options |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct($options = []) |
|
48
|
|
|
{ |
|
49
|
|
|
parent::__construct($options); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function initializeEngine($template = null) |
|
53
|
|
|
{ |
|
54
|
|
|
$xtpl = VENDOR_PATH . '/xtemplate/xtemplate.class.php'; |
|
55
|
|
|
|
|
56
|
|
|
// prevent redeclaration |
|
57
|
|
|
if (!class_exists('XTemplate', false)) { |
|
58
|
|
|
// check if library exists |
|
59
|
|
|
if (is_file($xtpl)) { |
|
60
|
|
|
include $xtpl; |
|
61
|
|
|
} else { |
|
62
|
|
|
throw new \Exception('The vendor library "XTemplate" is required.'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$template = $this->getTemplatePath($template); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
#\Koch\Debug\Debug::firebug('Xtemplate loaded with Template: ' . $template); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
// Do it with XTemplate style > eat like a bird, poop like an elefant! |
|
71
|
|
|
return $this->renderer = new self($template); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function configureEngine() |
|
75
|
|
|
{ |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function renderPartial($template) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function clearVars() |
|
83
|
|
|
{ |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function clearCache() |
|
87
|
|
|
{ |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function fetch($template, $data = null) |
|
91
|
|
|
{ |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function display($template, $data = null) |
|
95
|
|
|
{ |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Returns a clean xTemplate Object. |
|
100
|
|
|
* |
|
101
|
|
|
* @return Xtemplate Object |
|
|
|
|
|
|
102
|
|
|
*/ |
|
103
|
|
|
public function getEngine() |
|
104
|
|
|
{ |
|
105
|
|
|
// clear assigns? |
|
106
|
|
|
return $this->renderer; |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function render($template = null, $viewdata = null) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->renderer->assign($viewdata); |
|
112
|
|
|
$this->renderer->parse($template); |
|
113
|
|
|
$this->renderer->out($template); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function assign($tpl_parameter, $value = null) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->renderer->assign($tpl_parameter, $value); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: