|
| 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) |
| |
| static | getBasename ($filename, $suffix=true) |
| |
| static | getAbsoluteName ($filename, $base=null) |
| |
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)
- Copyright
- Copyright 2018 AV-RD e.U. (License: GNU General Public License (v3))
- See also
-
| 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::getAbsoluteName |
( |
|
$filename, |
|
|
|
$base = null |
|
) |
| |
|
static |
Resolves a given path relative to a given base, and returns the absolute path (+filename if given).
It's merely a call to realpath(), but works if the file doesn't exist (yet). BUT: The path must already exist!
- Parameters
-
| $filename | [string] Path or path+filename. |
| $base | [string] Folder to consider as base for relative $filename. |
| 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::getBasename |
( |
|
$filename, |
|
|
|
$suffix = true |
|
) |
| |
|
static |
Returns the basename of a file (without path).
- Parameters
-
| $filename | [string] Regular filename string, with or without path. |
| $suffix | [bool] Return filename without file suffix if 'false'. |
- Return values
-
| boolean | Returns 'true' if successful, 'False' if an error occurred. |
| 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
-
| Array | An 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
-
| Array | An 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
-
| Array | An 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
-
| Exception | If 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
-
| boolean | Returns '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 |
| 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:
- /home/pb/avrd/projects/cinbox/bin/include/Helper.php