tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Class: Tangra_File

Source Location: /filesystem_toolbox/tangra_file.class.php

Class Tangra_File

Class Overview

File operations wrapper class

Tangra_File is used as wrapper that will throw exceptions on error occured during file operations

Located in /filesystem_toolbox/tangra_file.class.php [line 58]

Tangra_Class
   |
   --Tangra_File

Properties

Methods

[ Top ]
Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From Tangra_Class

Tangra_Class::get_class_name()
Alias of get_class(). Exist because of historical reasons.
Tangra_Class::__set()
Overides PHP built-in method and just throws exception if called. Purpose - to "forbid" autosetting of nonexisting class properties.

[ Top ]
Property Summary
resource   $file_handle   Handle for the file
string   $file_name   File name
boolean   $open   Indicated that file is open

[ Top ]
Method Summary
Tangra_File   __construct()   Constructs the object
void   close()   Closes the file
string   get_file_name()   Returns file name
string   get_line()   Reads line from the file and returns it
void   open()   Opens the file.
boolean   read()   Reads up to $length bytes from the file pointer. Reading stops when up to $length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.
void   read_all()   Reads the whole file and returns it's content
void   write()   Writes the contents of $str to the file

[ Top ]
Properties
resource   $file_handle [line 73]

Handle for the file

API Tags:
Internal:  
Access:  private


[ Top ]
string   $file_name [line 65]

File name

API Tags:
Internal:  
Access:  private


[ Top ]
boolean   $open = false [line 81]

Indicated that file is open

API Tags:
Internal:  
Access:  private


[ Top ]
Methods
Constructor __construct  [line 103]

  Tangra_File __construct( string $file_name, [string $open_mode = NULL]  )

Constructs the object

If parameter $open_mode is passed - constructor will open the file.

  • 'r' - Open for reading only; place the file pointer at the beginning of the file.
  • 'r+' - Open for reading and writing; place the file pointer at the beginning of the file.
  • 'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
  • 'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
  • 'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
  • 'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
  • 'x' - Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.
  • 'x+' - Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.

Parameters:
string   $file_name: 
string   $open_mode: 


[ Top ]
close  [line 147]

  void close( )

Closes the file


API Tags:
Access:  public

Information Tags:
Throws:  TE_File_Close_Failed

[ Top ]
get_file_name  [line 116]

  string get_file_name( )

Returns file name


API Tags:
Access:  public


[ Top ]
get_line  [line 170]

  string get_line( )

Reads line from the file and returns it

Wrapper around PHP's fgets() Please note that newline sequences are included in return value so you may need to call trim() to get rif of them

If file pointer is at the end - returns NULL. If some error occures - throws TE_File_Get_Line_Failed


API Tags:
Access:  public

Information Tags:
Throws:  TE_File_Has_Not_Been_Open, TE_File_Get_Line_Failed

[ Top ]
open  [line 129]

  void open( unknown_type $mode  )

Opens the file.

See __construct for desctription of $mode parameter

Parameters:
unknown_type   $mode: 

API Tags:
Access:  public

Information Tags:
Throws:  TE_File_Open_Failed

[ Top ]
read  [line 194]

  boolean read( integer $length  )

Reads up to $length bytes from the file pointer. Reading stops when up to $length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.

Wrapper around PHP's fread() function Reads up to $length bytes from the file pointer. Reading stops when up to $length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.

Parameters:
integer   $length: 

API Tags:
Access:  public


[ Top ]
read_all  [line 239]

  void read_all( )

Reads the whole file and returns it's content


API Tags:
Access:  public


[ Top ]
write  [line 218]

  void write( string $str, [integer $length = NULL]  )

Writes the contents of $str to the file

Wrapper around PHP's fwrite() function Writes the contents of $str to the file. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.

Parameters:
string   $str: 
integer   $length: 

API Tags:
Access:  public

Information Tags:
Throws:  TE_File_Write_Failed, TE_File_Has_Not_Been_Open

[ Top ]