Class RSIO

Description

A Utility Class for IO Operations.

This class provides methods not included in PEARS's IO packages.

Located in /code/framework/RSIO/RSIO.php (line 49)


	
			
Method Summary
void copyDirectory (String $from_path, String $to_path, [mixed $overwrite = true])
void getFileContents (String $filename)
void replaceInAllFilenames (String $path, Array $replacements)
boolean replaceInFilename (String $path, Array $replacements)
Methods
copyDirectory (line 56)

Copies a directory including all subdirectories and files.

void copyDirectory (String $from_path, String $to_path, [mixed $overwrite = true])
  • String $from_path: Source: the directory to copy. MUST end with a slash.
  • String $to_path: Destination: where the direcotry specified by the first argument should be copied to. MUST end with a slash.
getFileContents (line 175)

Returns the contents of the file $filename or an instance of RSError if fopen failed.

This method allows to easyly retrieve the contents of a file without being incompatible to PHP versions < 4.3.0 as the native method file_get_contents is. getFileContents uses http://www.php.net/fopen to retrieve a file handle. This method avoids the overhead of PEAR::File and it has the advantage that you do not have to call any rewind method as you have to do in PEAR::File before executing another 'readAll'-operation on the same file. Example:


1 $contents = RSIO::getFileContents('/my_path/my_file.txt');
2 if (PEAR::isError($contents) {
3 //error handling
4 } else {
5 echo $contents;
6 }

void getFileContents (String $filename)
  • String $filename: A filename valid for fopen
replaceInAllFilenames (line 136)

Renames all files and directories in $path recursively by doing a string replacement.

RSIO::replaceInFilename is called for each file and directory to do the actual replacement. See RSIO::replaceInFilename for details.

void replaceInAllFilenames (String $path, Array $replacements)
  • String $path: The path to the directory where to start the operation.
  • Array $replacements: An associative array of search and replacement strings as key-value pairs.
replaceInFilename (line 107)

Renames a file by doing a string replacement.

Example:


1 RSIO::replaceInFilename(
2 '/mypath/tyops_to_be_repalced.txt',
3 array(
4 'repalce' => 'replace',
5 'tyop' => 'typo'
6 )
7 );
This would rename /mypath/tyops_to_be_repalced.txt to /mypath/typos_to_be_replaced.txt.

  • return: True on success, false on failure. Note that if the filename does not contain one of the search strings the file is not renamed and true is returned.
boolean replaceInFilename (String $path, Array $replacements)
  • String $path: The path to the file.
  • Array $replacements: An associative array of search and replacement strings as key-value pairs.

Documentation generated on Mon, 8 Dec 2003 13:13:08 +0100 by phpDocumentor 1.2.3