TITAN Library for PHP5  5.1.0
Web Software Development Kit for PHP5
file Class Reference

Titan File Class. More...

Public Member Functions

 __construct ($filename= '', $lock=true, $expire_time= '+1 minute')
 
 read ($filename= '', $as_string=false, $lock=true)
 
 write ($mode, $content= '', $filename= '')
 
 fopen ($mode= 'r', $filename= '', $lock=true)
 
 fclose ()
 
 fwrite ($string= '')
 

Data Fields

 $expire_time = '+1 minute'
 How long before the lock expires?
 
 $error = ''
 Error message, if any.
 

Protected Attributes

 $lock = false
 Lock object.
 
 $use_lock = false
 Are we using a lock?
 
 $filename = ''
 Name of the file to read/write.
 
 $exists = false
 Does the file already exist? boolean.
 
 $fp = false
 Internal: file pointer.
 
 $lines = false
 Set by $this->read() - array of lines in the file content.
 

Detailed Description

Titan File Class.

Class: \tl\io\file

Author
James E. Bush work@.nosp@m.bush.nosp@m..cc
Version
5.1.0

Constructor & Destructor Documentation

__construct (   $filename = '',
  $lock = true,
  $expire_time = '+1 minute' 
)

Constructor

Parameters
string$filename(optional) Name of the file to access (default) '' - you must set it later (i.e. in a foreach of an array of filenames)
                                            $file->filename = '/path/to/filename';
                                                or
                                            $content = $file->read('/path/to/filename');
                                                or
                                            $file->write('w', $content, '/path/to/filename');
*
boolean$lock(optional) Should we use a lock for file accesses? (default) true = use lock
string$expire_time(optional) How long before the lock expires? (default) '+1 minute'
Returns
file File manipulation object

Member Function Documentation

read (   $filename = '',
  $as_string = false,
  $lock = true 
)

lock, open, read, close, unlock

Parameters
string$filename(optional) Name of the file to access (default) '', use $this->filename. If $filename amd $this->filename are empty, this fails with error.
boolean$as_string(optional) Should we return the contents as a combined string? (default) false ; true = combined string ; false = array of strings
boolean$lock(optional) Should we use a lock for file accesses? (default) true = use lock (if a lock was created in the constructor!)
write (   $mode,
  $content = '',
  $filename = '' 
)

lock, open, write, close, unlock

Parameters
string$modeFile open mode (see PHP fopen())
string$content(optional) The content to write (default) '', the content is not written. The file is still opened and may be truncated, depending on $mode.
string$filename(optional) Name of the file to access (default) '', use $this->filename. If $filename amd $this->filename are empty, this fails with error.
Returns
boolean The result of fclose();
fopen (   $mode = 'r',
  $filename = '',
  $lock = true 
)

Lock the file and open

Parameters
string$mode(optional) File open mode (see PHP fopen()) (default) 'r', read-only
string$filename(optional) Name of the file to access (default) '', use $this->filename. If $filename amd $this->filename are empty, this fails with error.
boolean$lock(optional) Should we use a lock for file accesses? (default) true = use lock (if a lock was created in the constructor!)
Returns
resource The internal file pointer
fclose ( )

Close the file and unlock

Returns
boolean Success or failure
fwrite (   $string = '')

Write to an open file

Parameters
string$string(optional) The text string to write (default) '', nothing is written.

The documentation for this class was generated from the following file: