MkFramework
 All Data Structures Functions
class_layout.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 class _layout{
24 
25  private $_tContent;
26  private $_sLayout;
27  private $_tVar;
28 
34  public function __construct($sLayout=null){
35 
36  $this->_tVar=array();
37 
38  /*LOG*/_root::getLog()->info('--layout: initialisation ['.$sLayout.']');
39  if($sLayout==null){ throw new Exception('layout non definit dans le constructeur :(');}
40  $this->setLayout($sLayout);
41  }
42 
46  public function __set($sVar, $sVal){
47  /*LOG*/_root::getLog()->info('---layout: assignation ['.$sVar.']');
48  $this->_tVar[$sVar]=$sVal;
49  }
53  public function __get($sVar){
54  if(!array_key_exists($sVar,$this->_tVar)){
55  /*LOG*/_root::getLog()->error('Variable '.$sVar.' inexistante dans le layout '.$this->_sLayout);
56  throw new Exception('Variable '.$sVar.' inexistante dans le layout '.$this->_sLayout);
57  }else{
58  return $this->_tVar[$sVar];
59  }
60  }
61 
65  public function __isset($sVar){
66  return isset($this->_tVar[$sVar]);
67  }
68 
72  public function __unset($sVar){
73  unset($this->_tVar[$sVar]);
74  }
75 
81  public function setLayout($sLayout){
82  /*LOG*/_root::getLog()->info('-layout: choix de ['._root::getConfigVar('path.layout').$sLayout.'.php]');
83  $this->_sLayout=$sLayout;
84  }
85 
92  public function add($sPlace,$oTpl){
93  /*LOG*/_root::getLog()->info('-layout: ajout appel vue ['.$oTpl->getPath().'] a la place ['.$sPlace.']');
94  $this->_tContent[$sPlace][]=$oTpl;
95  }
102  public function addModule($sPlace,$sAppel){
103  /*LOG*/_root::getLog()->info('-layout: ajout appel module ['.$sAppel.'] a la place ['.$sPlace.']');
104  list($sModule,$sAction)= preg_split('/::/',$sAppel);
105  $sModule='module_'.$sModule;
106  $oModule=new $sModule;
107  $this->_tContent[$sPlace][]=call_user_func( array($oModule,'_'.$sAction));
108  }
113  public function show(){
114  /*LOG*/_root::getLog()->info('-layout: affichage ['._root::getConfigVar('path.layout').$this->_sLayout.'.php]');
115  if(!file_exists( _root::getConfigVar('path.layout').$this->_sLayout.'.php')){
116  $tErreur=array(
117  'layout '.$this->_sLayout.' introuvable dans '._root::getConfigVar('path.layout'),
118  _root::getConfigVar('path.layout').$this->_sLayout.'.php introuvable',
119  );
120  throw new Exception(implode("\n",$tErreur));
121  }
122  include _root::getConfigVar('path.layout').$this->_sLayout.'.php';
123  }
128  public function getOutput(){
129 
130  /*LOG*/_root::getLog()->info('-layout: getOutput ['._root::getConfigVar('path.layout').$this->_sLayout.'.php]');
131  if(!file_exists( _root::getConfigVar('path.layout').$this->_sLayout.'.php')){
132  $tErreur=array(
133  'layout '.$this->_sLayout.' introuvable dans '._root::getConfigVar('path.layout'),
134  _root::getConfigVar('path.layout').$this->_sLayout.'.php introuvable',
135  );
136  throw new Exception(implode("\n",$tErreur));
137  }
138  ob_start();
139  include _root::getConfigVar('path.layout').$this->_sLayout.'.php';
140 
141  $sSortie=ob_get_contents();
142  ob_end_clean();
143 
144  return $sSortie;
145  }
146 
153  public function load($sPlace){
154  /*LOG*/_root::getLog()->info('-layout: chargement/affichage place ['.$sPlace.']');
155  if(!isset($this->_tContent[$sPlace])){ return null;}
156  $sLoad='';
157  foreach($this->_tContent[$sPlace] as $oTpl){
158  $sLoad.=$oTpl->show();
159  }
160  return $sLoad;
161  }
162 }
add($sPlace, $oTpl)
__set($sVar, $sVal)
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
addModule($sPlace, $sAppel)
__isset($sVar)
setLayout($sLayout)
__unset($sVar)
__get($sVar)
__construct($sLayout=null)
static getLog()
Definition: class_root.php:610
load($sPlace)