Constants

FOLDER_SEPARATOR

FOLDER_SEPARATOR

Separator character for paths.

EOL_WIN

EOL_WIN

Line terminator for Windows.

EOL_UNIX

EOL_UNIX

Line terminator for Linux.

CSV_FIELD_DELIMITER

CSV_FIELD_DELIMITER

CSV default field delimiter.

CSV_FIELD_QUOTE

CSV_FIELD_QUOTE

CSV default field quote.

CSV_FIELD_QUOTE_ESCAPE

CSV_FIELD_QUOTE_ESCAPE

CSV default field quote escape.

Methods

cryptApr1Md5()

cryptApr1Md5(string  $plainpasswd) : string

APR1-MD5 encryption method (Windows compatible).

Parameters

string $plainpasswd

The password to encrypt in plain text.

Returns

string —

Encrypted password (hash).

writeToFile()

writeToFile(string  $path, string  $content, string  $mode = "w") : boolean

Method handling file write operation.

Parameters

string $path

File/path to write to

string $content

String to write

string $mode

Write mode (fopen), "w" or "a", default "w"

Returns

boolean —

true if successful

sanitizeFilename()

sanitizeFilename(string  $name) : string

Simple filename sanitizer. Purges characters other than alphanumeric, hyphen, underscore and dot.

Parameters

string $name

Returns

string —

The sanitized string.

sanitizePath()

sanitizePath(string  $path) : string

File path sanitizer:

  • Convert all separator characters for paths to FOLDER_SEPARATOR
  • Correct separator count
  • Correct dot count
  • Whitelist permitted characters, OS dependent (sift out everything else). For Windows: Alphanumeric, hyphen, underscore, colon, dot, space, German umlauts. For Linux or any other OS: Alphanumeric, hyphen, underscore, tilde, dot.
  • Harmonize trailing directory separator (make sure one is in place regardless of original path)

Parameters

string $path

Returns

string —

The sanitized path string.

pathLeavesOrEqualsRoot()

pathLeavesOrEqualsRoot(string  $path, string  $root) : boolean

Make sure a given path does at no time leave or become equal to another path (aka "the document root"):

  • Ensure that the first N characters of $path are exactly the same as $root, reject up-front if not
  • If true, allow for OS agnostic level search (eg. snip away leading Win C:)
  • The first time $path goes above $root, reject it
  • If $path ends up at the same level as $root, reject it

Parameters

string $path

The path to validate

string $root

The path representing document root

Returns

boolean

pathHelperCutLeadingSeparator()

pathHelperCutLeadingSeparator(  $path) 

Parameters

$path

pathHelperHarmonizeTrailingSeparator()

pathHelperHarmonizeTrailingSeparator(string  $path) : string

Harmonize trailing directory separator (make sure one is in place regardless of original path).

Parameters

string $path

Returns

string

pathDepth()

pathDepth(string  $path) : integer

Calculate the depth (i.e. number of portions divided by FOLDER_SEPARATOR) of a given path.

Parameters

string $path

Returns

integer

isWin()

isWin() : boolean

Check if OS running the script is Win or Linux.

Returns

boolean

getOsEol()

getOsEol() : string

Return OS specific line terminator.

Returns

string

content2CSV()

content2CSV(array  $content, array  $params = null) : array

CSV representation of the given content.

Parameters

array $content

Associative array containing all fields to write, field names as keys, field content as values (representing a logfile entry).

array $params

CSV parameter: "field_delimiter" (default -> ,), "field_quote" (default -> "), "field_quote_escape" (default -> ").

Returns

array —

Associative, "field_names" -> csv string of field IDs, "field_content" -> csv string of log field contents

isAbsolutePath()

isAbsolutePath(string  $target) : boolean

Simple check if given path is absolute (leading folder separator is present or not).

Parameters

string $target

Path to check.

Returns

boolean —

True if path is absolute, false if not.

separatePathAndFile()

separatePathAndFile(string  $target) : array

Separate given $target into path and filename.

Parameters

string $target

Path + filename to separate.

Returns

array —

Assoc. array, "pathname" contains path, "filename" contains file portion.

cleanupPath()

cleanupPath(string  $target) : string

Clear a given $target path of single dots, empty portions between folder separators and purify double dot parts

Parameters

string $target

Path to cleanup

Returns

string —

Purified path.

strStartsWith()

strStartsWith(  $haystack,   $needle) 

Parameters

$haystack
$needle

strEndsWith()

strEndsWith(  $haystack,   $needle) 

Parameters

$haystack
$needle