ultimix
cached_fs.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $MountedStorages = false;
39 
50  var $Cache;
51 
66  function cached_fs_1_0_0()
67  {
68  try
69  {
70  $this->Cache = get_package( 'cache' , 'last' , __FILE__ );
71  }
72  catch( Exception $e )
73  {
74  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
75  }
76  }
77 
92  function reset()
93  {
94  try
95  {
96  $this->Cache->reset();
97  }
98  catch( Exception $e )
99  {
100  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
101  }
102  }
103 
130  function store_file_exists_info( $OriginalFilePath , $ExistsFlag )
131  {
132  try
133  {
134  if( $ExistsFlag !== false )
135  {
136  return( true );
137  }
138  else
139  {
140  $this->Cache->add_data( $OriginalFilePath , '_file_was_not_found' );
141  return( false );
142  }
143  }
144  catch( Exception $e )
145  {
146  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
147  }
148  }
149 
172  function file_exists( $OriginalFilePath )
173  {
174  try
175  {
176  $OriginalFilePath = str_replace( '/./' , '/' , $OriginalFilePath );
177  $Data = $this->Cache->get_data( $OriginalFilePath );
178 
179  if( $Data === false )
180  {
181  return( $this->store_file_exists_info( $OriginalFilePath , file_exists( $OriginalFilePath ) ) );
182  }
183  else
184  {
185  return( $Data == '_file_was_not_found' ? false : true );
186  }
187  }
188  catch( Exception $e )
189  {
190  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
191  }
192  }
193 
216  function file_get_contents( $OriginalFilePath )
217  {
218  try
219  {
220  $OriginalFilePath = str_replace( '/./' , '/' , $OriginalFilePath );
221  $Data = $this->Cache->get_data( $OriginalFilePath );
222  if( $Data !== false )
223  {
224  return( $Data );
225  }
226  else
227  {
228  $Data = @file_get_contents( $OriginalFilePath );
229  if( $Data !== false )
230  {
231  $this->Cache->add_data( $OriginalFilePath , $Data );
232  return( $Data );
233  }
234  else
235  {
236  throw( new Exception( "File $OriginalFilePath was not found" ) );
237  }
238  }
239  }
240  catch( Exception $e )
241  {
242  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
243  }
244  }
245 
268  function file_put_contents( $OriginalFilePath , $Data )
269  {
270  try
271  {
272  $OriginalFilePath = str_replace( '/./' , '/' , $OriginalFilePath );
273  if( $this->Cache->data_exists( $OriginalFilePath ) )
274  {
275  $this->Cache->set_data( $OriginalFilePath , $Data );
276  }
277  else
278  {
279  $this->Cache->add_data( $OriginalFilePath , $Data );
280  }
281 
282  @file_put_contents( $OriginalFilePath , $Data );
283  }
284  catch( Exception $e )
285  {
286  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
287  }
288  }
289 
304  function flush()
305  {
306  try
307  {
308  $this->Cache->flush();
309  }
310  catch( Exception $e )
311  {
312  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
313  }
314  }
315  }
316 
317 ?>