MkFramework
 All Data Structures Functions
class_file.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 _file{
24 
25  private $_sAdresse;
26  private $_sContent;
27 
33  public function __construct($sAdresse=null){
34  if($sAdresse!=null){
35  $this->setAdresse($sAdresse);
36  }
37  $this->_sContent=null;
38  }
44  public function isDir(){
45  return false;
46  }
52  public function isFile(){
53  return true;
54  }
60  public function setAdresse($sAdresse){
61  if($sAdresse!=null){
62  $this->_sAdresse=$sAdresse;
63  }
64  }
70  public function getAdresse(){
71  return $this->_sAdresse;
72  }
78  public function setContent($sContent){
79  $this->_sContent=$sContent;
80  }
86  public function addContent($sContent){
87  $this->_sContent.=$sContent;
88  }
93  public function save($sOption='w'){
94  $this->write($this->_sContent,$sOption);
95  }
101  public function getContent(){
102  $this->verif();
103 
104  $sFichier=file_get_contents($this->_sAdresse);
105 
106  return $sFichier;
107  }
112  public function load(){
113  $this->_sContent=$this->getContent();
114  }
119  public function clean(){
120  $this->_sContent=null;
121  $this->_sAdresse=null;
122  }
128  public function getTab(){
129  $this->verif();
130 
131  return file($this->_sAdresse);
132  }
137  public function delete(){
138  $this->verif();
139 
140  unlink($this->_sAdresse);
141  }
147  public function exist(){
148  return file_exists($this->_sAdresse);
149  }
155  public function getName(){
156  $this->verif();
157  return basename($this->_sAdresse);
158  }
164  public function getExtension(){
165  $this->verif();
166  $tTmp=preg_split('/\./',$this->_sAdresse);
167  return end($tTmp);
168  }
175  public function write($sContent,$sOption='w'){
176 
177  if($sContent==''){
178  file_put_contents($this->_sAdresse,$sContent);
179  }else if(!file_put_contents($this->_sAdresse,$sContent)){
180  throw new Exception('Can t write "'.$sContent.'"'.$this->_sAdresse);
181  }
182  }
188  public function filemtime(){
189  return filemtime($this->_sAdresse);
190  }
196  public function chmod($iVal=0777){
197  chmod($this->_sAdresse,$iVal);
198  }
199 
200  private function verif(){
201  if(!$this->exist()){
202  throw new Exception($this->_sAdresse.' n\'existe pas');
203  }
204  return true;
205  }
206 
207 }
getExtension()
Definition: class_file.php:164
__construct($sAdresse=null)
Definition: class_file.php:33
getName()
Definition: class_file.php:155
setContent($sContent)
Definition: class_file.php:78
write($sContent, $sOption='w')
Definition: class_file.php:175
setAdresse($sAdresse)
Definition: class_file.php:60
save($sOption='w')
Definition: class_file.php:93
isDir()
Definition: class_file.php:44
getTab()
Definition: class_file.php:128
getAdresse()
Definition: class_file.php:70
getContent()
Definition: class_file.php:101
addContent($sContent)
Definition: class_file.php:86
chmod($iVal=0777)
Definition: class_file.php:196
isFile()
Definition: class_file.php:52
filemtime()
Definition: class_file.php:188