MkFramework
 All Data Structures Functions
class_dir.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 _dir{
24 
25  private $_sAdresse=null;
26 
32  public function __construct($sAdresse=null){
33  if($sAdresse!=null){
34  $this->setAdresse($sAdresse);
35  }
36  }
42  public function isDir(){
43  return true;
44  }
50  public function isFile(){
51  return false;
52  }
58  public function setAdresse($sAdresse){
59  if($sAdresse!=null){
60  $this->_sAdresse=$sAdresse;
61  }
62  }
68  public function getAdresse(){
69  return $this->_sAdresse;
70  }
71 
77  public function getName(){
78  $this->verif();
79  return basename($this->_sAdresse);
80  }
90  public function getList($tInclusion=null,$tExclusion=null,$bWithHidden=false){
91  $this->verif();
92 
93  $open=openDir($this->_sAdresse);
94 
95  $tFile=array();
96 
97  while(false !== ($sFile=readDir($open)) ){
98 
99  $bIsDir=is_dir($this->_sAdresse.'/'.$sFile);
100  $tDetailFile=preg_split('/\./',$sFile);
101 
102  if($bWithHidden==false and $sFile[0]=='.'){
103  continue;
104  }elseif($bIsDir==true){
105  $oElement=new _dir($this->_sAdresse.'/'.$sFile);
106  $tFile[]=$oElement;
107  }elseif(
108  ($tInclusion==null or in_array(end($tDetailFile),$tInclusion))
109  and
110  ($tExclusion==null or !in_array(end($tDetailFile),$tExclusion))
111  ){
112  $oElement=new _file($this->_sAdresse.'/'.$sFile);
113  $tFile[]=$oElement;
114 
115  }
116 
117 
118  }
119 
120  return $tFile;
121  }
129  public function getListFile($tInclusion=null,$tExclusion=null,$bWithHidden=false){
130  $this->verif();
131 
132  $open=openDir($this->_sAdresse);
133 
134  $tFile=array();
135 
136  while(false !== ($sFile=readDir($open)) ){
137 
138  $bIsDir=is_dir($this->_sAdresse.'/'.$sFile);
139  $tDetailFile=preg_split('/\./',$sFile);
140 
141  if($bWithHidden==false and $sFile[0]=='.'){
142  continue;
143 
144  }elseif(
145  $bIsDir==false
146  and ($tInclusion==null or in_array(end($tDetailFile),$tInclusion))
147  and ($tExclusion==null or !in_array(end($tDetailFile),$tExclusion))
148 
149  ){
150  $oElement=new _file($this->_sAdresse.'/'.$sFile);
151  $tFile[]=$oElement;
152 
153  }
154 
155 
156  }
157 
158  return $tFile;
159  }
167  public function getListDir($bWithHidden=false){
168  $this->verif();
169 
170  $open=openDir($this->_sAdresse);
171 
172  $tFile=array();
173 
174  while(false !== ($sFile=readDir($open)) ){
175 
176  $bIsDir=is_dir($this->_sAdresse.'/'.$sFile);
177 
178  if($bWithHidden==false and $sFile[0]=='.'){
179  continue;
180  }elseif($bIsDir==true){
181  $oElement=new _dir($this->_sAdresse.'/'.$sFile);
182  $tFile[]=$oElement;
183  }
184 
185 
186  }
187 
188  return $tFile;
189  }
194  public function delete(){
195  $this->verif();
196 
197  if(!@rmdir($this->_sAdresse)){
198  throw new Exception('Erreur rmdir ('.$this->_sAdresse.')');
199  }
200  }
206  public function exist(){
207  return file_exists($this->_sAdresse);
208  }
213  public function save(){
214  mkdir($this->_sAdresse);
215  }
220  public function chmod($valeur=0777){
221  chmod($this->_sAdresse,$valeur);
222  }
223 
224  private function verif(){
225 
226  if($this->_sAdresse==null){
227  throw new Exception('objet _dir: Adresse du repertoire non defini');
228  }
229 
230  if(!$this->exist()){
231  throw new Exception($this->_sAdresse.' n\'existe pas');
232  }
233  }
234 }
__construct($sAdresse=null)
Definition: class_dir.php:32
getListFile($tInclusion=null, $tExclusion=null, $bWithHidden=false)
Definition: class_dir.php:129
getName()
Definition: class_dir.php:77
exist()
Definition: class_dir.php:206
setAdresse($sAdresse)
Definition: class_dir.php:58
getList($tInclusion=null, $tExclusion=null, $bWithHidden=false)
Definition: class_dir.php:90
isFile()
Definition: class_dir.php:50
chmod($valeur=0777)
Definition: class_dir.php:220
isDir()
Definition: class_dir.php:42
getAdresse()
Definition: class_dir.php:68
getListDir($bWithHidden=false)
Definition: class_dir.php:167
save()
Definition: class_dir.php:213