forked from imikado/mkframeworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_view.php
More file actions
118 lines (101 loc) · 2.99 KB
/
class_view.php
File metadata and controls
118 lines (101 loc) · 2.99 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
This file is part of Mkframework.
Mkframework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License.
Mkframework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* classe _tpl
* @author Mika
* @link http://mkf.mkdevs.com/
*/
class _view{
protected $_sModule;
protected $_sTpl;
protected $_tVar;
protected $_sPath;
/**
* constructeur
* @access public
* @param string $sRessource nom du fichier de template a utiliser (module::fichier)
*/
public function __construct($sRessource=null){
$this->_tVar=array();
/*LOG*/_root::getLog()->info('--vue: initialisation ['.$sRessource.']');
if($sRessource!=null){
if(preg_match('/::/',$sRessource)){
list($this->_sModule,$this->_sTpl)=preg_split('/::/',$sRessource);
$sRessource=_root::getConfigVar('path.module').$this->_sModule.'/';
$sRessource.=_root::getConfigVar('path.view','tpl/').$this->_sTpl.'.php';
}
$this->choose($sRessource);
}
}
public function __set($sVar, $sVal){
/*LOG*/_root::getLog()->info('---vue: assignation ['.$sVar.']');
$this->_tVar[$sVar]=$sVal;
}
public function __get($sVar){
if(!array_key_exists($sVar,$this->_tVar)){
/*LOG*/_root::getLog()->error('Variable '.$sVar.' inexistante dans le template '.$this->_sModule.'::'.$this->_sTpl);
throw new Exception('Variable '.$sVar.' inexistante dans le template '.$this->_sModule.'::'.$this->_sTpl);
}else{
return $this->_tVar[$sVar];
}
}
/**
* isset
*/
public function __isset($sVar){
return isset($this->_tVar[$sVar]);
}
/**
* unset
*/
public function __unset($sVar){
unset($this->_tVar[$sVar]);
}
/**
* retourne la sortie
* @access public
* @return string
*/
public function show(){
/*LOG*/_root::getLog()->info('--vue: affichage ['.$this->_sPath.']');
ob_start();
include $this->_sPath;
$sSortie=ob_get_contents();
ob_end_clean();
return $sSortie;
}
/**
* retourne le path de la vue
* @access public
* @return string
*/
public function getPath(){
return $this->_sPath;
}
/**
* retourne un lien framework
* @access public
* @return string
*/
public function getLink($sLink,$tParam=null,$bAmp=true){
return _root::getLink($sLink,$tParam,$bAmp);
}
protected function choose($sPath){
if(!file_exists($sPath) and !file_exists($sPath._root::getConfigVar('template.extension'))){
/*LOG*/_root::getLog()->error('vue '.$sPath.' et inexistant');
throw new Exception('vue '.$sPath.' et '.$sPath._root::getConfigVar('template.extension').' inexistant');
}
$this->_sPath=$sPath;
}
}