CInbox (Common-Inbox)  0.1
Common functionality for ingesting files for archiving.
Static Public Member Functions | List of all members
Helper Class Reference

Static Public Member Functions

static resolveString ($masked, $arguments)
 
static touchFile ($fileName)
 
static isAbsolutePath ($pathName)
 
static getPhpUser ()
 
static getSubFolderArray ($folderName, $maxDepth=99, $depth=0)
 
static removeEmptySubfolders ($folderName)
 
static removeFolder ($folderName)
 
static getTargetFilename ($sourceFile, $targetFolder)
 
static getAsRelativePath ($pathName, $baseFolder)
 
static appendTextfiles ($file1, $file2)
 
static getYoungest ($folder)
 
static isFolderEmpty ($folder)
 
static getFolderListing ($folder)
 
static getFolderListing2 ($folder)
 
static getRecursiveFolderListing ($folder, $flags=null)
 
static dirlistToText ($list, $filter_keys=null)
 
static arrayDiffKey ($array1, $array2)
 
static getStats ($filename)
 

Detailed Description

This class contains functions that just don't fit anywhere else. Or that are simply useful in many different places ;)

Methods in here are preferred to be static, so they can be used without requiring an instance of 'Helper'.

Author
Peter Bubestinger-Steindl (pb@av.nosp@m.-rd..nosp@m.com)
See also

Member Function Documentation

static Helper::appendTextfiles (   $file1,
  $file2 
)
static

Reads 2 textfiles into an array, appending contents of $file2 after contents of $file1. Returns the result as one unified array.

static Helper::arrayDiffKey (   $array1,
  $array2 
)
static

Compares 2 arrays by keys and returns the difference.

It uses PHP's "array_diff_key()", but it properly returns the difference even if the first array is empty.

static Helper::dirlistToText (   $list,
  $filter_keys = null 
)
static

Converts an array with filenames as keys into a simple plaintext string listing.

Can be used on the return arrays of getFolderListing() or getRecursiveFolderListing().

Parameters
$filter_keys[array] List of keys to filter/remove from listing.
static Helper::getAsRelativePath (   $pathName,
  $baseFolder 
)
static

Returns $pathName's path as relative to $baseFolder.

$pathName can be a folder or filename, but the path must start with $baseFolder in order to return a valid result.

static Helper::getFolderListing (   $folder)
static

Creates an unfiltered directory listing using #DirectoryIterator, but returns the listing as array. Dots ('.' and '..') are excluded from the list.

The array contains the filenames as keys and the directory entries as SplFileInfo objects as values. Therefore, if you want to sort the list alphabetically, use PHP's "ksort()" function.

Return values
ArrayAn array of entries of $folder. key = SplFileInfo::getFilename() value = DirectoryIterator object (extends SplFileInfo)
static Helper::getFolderListing2 (   $folder)
static

Same functionality as getFolderListing(), but different output format!

Return values
ArrayAn array of entries of $folder. key = Absolute path+filename value = Output of stat() for the file
static Helper::getPhpUser ( )
static

Returns the name of the user the PHP process is running as.

static Helper::getRecursiveFolderListing (   $folder,
  $flags = null 
)
static

Similar to getFolderListing(), but recurses through subfolders.

Supports some flags, borrowed from glob(): GLOB_ONLYDIR: List only directories. No files.

Return values
ArrayAn array of entries of $folder. key = SplFileInfo::getFilename() value = DirectoryIterator object (extends SplFileInfo)
static Helper::getStats (   $filename)
static

Wrapper to PHP's internal stat() function. Throws an exception if stat() call was not successful.

Exceptions
ExceptionIf stat() call was not successful.
static Helper::getSubFolderArray (   $folderName,
  $maxDepth = 99,
  $depth = 0 
)
static

Creates an array with all subfolders of $folderName. The paths within the array are absolute.

static Helper::getTargetFilename (   $sourceFile,
  $targetFolder 
)
static

Generates and returns the proper filename in the target folder for the given source file. Returns 'false' on error.

static Helper::getYoungest (   $folder)
static

Searches the youngest file/folder found in $folder. Returns it as SplFileInfo object.

static Helper::isAbsolutePath (   $pathName)
static

Checks if the given path name is an absolute or relative path, by checking if it starts with a DIRECTORY_SEPARATOR character. Returns 'true' if path is absolute, 'false' if relative.

static Helper::isFolderEmpty (   $folder)
static

Checks if a folder is empty.

Return values
booleanReturns 'true' if folder is empty. 'False' if not.
static Helper::removeEmptySubfolders (   $folderName)
static

Recurse through a folder structure and remove all empty subfolders. Returns 'true' if all folders were empty. 'false' if not.

static Helper::removeFolder (   $folderName)
static

Recurse through a folder structure and remove it - including subfolders. Returns 'true' if the folder could be removed successfully, 'false' if not.

(Based on code from: http://stackoverflow.com/posts/3352564/revisions)

static Helper::resolveString (   $masked,
  $arguments 
)
static

Resolves a mask-string to its final value by replacing all placeholders using the provided $arguments array containing a "placeholder=>value" mapping.

static Helper::touchFile (   $fileName)
static

Creates subfolders for the path of $fileName if they don't already exists and tries to 'touch' the file. Used to check before attempting to write to $fileName.


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