-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass_layout.php
More file actions
162 lines (145 loc) · 4.62 KB
/
class_layout.php
File metadata and controls
162 lines (145 loc) · 4.62 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?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 _layout pour gerer le layout
* @author Mika
* @link http://mkf.mkdevs.com/
*/
class _layout{
private $_tContent;
private $_sLayout;
private $_tVar;
/**
* constructeur
* @access public
* @param string $sLayout nom du layout a utiliser
*/
public function __construct($sLayout=null){
$this->_tVar=array();
/*LOG*/_root::getLog()->info('--layout: initialisation ['.$sLayout.']');
if($sLayout==null){ throw new Exception('layout non definit dans le constructeur :(');}
$this->setLayout($sLayout);
}
/**
* setter
*/
public function __set($sVar, $sVal){
/*LOG*/_root::getLog()->info('---layout: assignation ['.$sVar.']');
$this->_tVar[$sVar]=$sVal;
}
/**
* getter
*/
public function __get($sVar){
if(!array_key_exists($sVar,$this->_tVar)){
/*LOG*/_root::getLog()->error('Variable '.$sVar.' inexistante dans le layout '.$this->_sLayout);
throw new Exception('Variable '.$sVar.' inexistante dans le layout '.$this->_sLayout);
}else{
return $this->_tVar[$sVar];
}
}
/**
* isset
*/
public function __isset($sVar){
return isset($this->_tVar[$sVar]);
}
/**
* unset
*/
public function __unset($sVar){
unset($this->_tVar[$sVar]);
}
/**
* forcer le layout
* @access public
* @param string $sLayout nom du layout a utiliser
*/
public function setLayout($sLayout){
/*LOG*/_root::getLog()->info('-layout: choix de ['._root::getConfigVar('path.layout').$sLayout.'.php]');
$this->_sLayout=$sLayout;
}
/**
* ajoute un objet _tpl $oTpl a l'emplacement $sPlace
* @access public
* @param string $sPlace emplacement
* @param _tpl $oTpl objet _tpl
*/
public function add($sPlace,$oTpl){
/*LOG*/_root::getLog()->info('-layout: ajout appel vue ['.$oTpl->getPath().'] a la place ['.$sPlace.']');
$this->_tContent[$sPlace][]=$oTpl;
}
/**
* ajoute l'appel a un module (module::action) a l'emplacement $sPlace
* @access public
* @param string $sPlace emplacement
* @param string $sAppel appel du module module::action
*/
public function addModule($sPlace,$sAppel){
/*LOG*/_root::getLog()->info('-layout: ajout appel module ['.$sAppel.'] a la place ['.$sPlace.']');
list($sModule,$sAction)= preg_split('/::/',$sAppel);
$sModule='module_'.$sModule;
$oModule=new $sModule;
$this->_tContent[$sPlace][]=call_user_func( array($oModule,'_'.$sAction));
}
/**
* affiche le layout et son contenu
* @access public
*/
public function show(){
/*LOG*/_root::getLog()->info('-layout: affichage ['._root::getConfigVar('path.layout').$this->_sLayout.'.php]');
if(!file_exists( _root::getConfigVar('path.layout').$this->_sLayout.'.php')){
$tErreur=array(
'layout '.$this->_sLayout.' introuvable dans '._root::getConfigVar('path.layout'),
_root::getConfigVar('path.layout').$this->_sLayout.'.php introuvable',
);
throw new Exception(implode("\n",$tErreur));
}
include _root::getConfigVar('path.layout').$this->_sLayout.'.php';
}
/**
* recupere le layout et son contenu
* @access public
*/
public function getOutput(){
/*LOG*/_root::getLog()->info('-layout: getOutput ['._root::getConfigVar('path.layout').$this->_sLayout.'.php]');
if(!file_exists( _root::getConfigVar('path.layout').$this->_sLayout.'.php')){
$tErreur=array(
'layout '.$this->_sLayout.' introuvable dans '._root::getConfigVar('path.layout'),
_root::getConfigVar('path.layout').$this->_sLayout.'.php introuvable',
);
throw new Exception(implode("\n",$tErreur));
}
ob_start();
include _root::getConfigVar('path.layout').$this->_sLayout.'.php';
$sSortie=ob_get_contents();
ob_end_clean();
return $sSortie;
}
/**
* retourne le contenu d'un objet _tpl a l'emplacement $sPlace
* @access public
* @return string
* @param string $sPlace
*/
public function load($sPlace){
/*LOG*/_root::getLog()->info('-layout: chargement/affichage place ['.$sPlace.']');
if(!isset($this->_tContent[$sPlace])){ return null;}
$sLoad='';
foreach($this->_tContent[$sPlace] as $oTpl){
$sLoad.=$oTpl->show();
}
return $sLoad;
}
}