Util
in package
The Util:: class provides generally useful methods.
Copyright 1999-2017 Horde LLC (http://www.horde.org/)
See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Tags
Table of Contents
- $patterns : array<string|int, mixed>
- A list of random patterns to use for overwriting purposes.
- $cache : array<string|int, mixed>
- Cache for extensionExists().
- $shutdowndata : array<string|int, mixed>
- Data used to determine shutdown deletion.
- $shutdownreg : bool
- Has the shutdown method been registered?
- createTempDir() : string
- Creates a temporary directory in the system's temporary directory.
- deleteAtShutdown() : mixed
- Removes given elements at request shutdown.
- extensionExists() : bool
- Caches the result of extension_loaded() calls.
- formInput() : string
- Returns a hidden form input containing the session name and id.
- getFormData() : string
- Gets a form variable from GET or POST data, stripped of magic quotes if necessary. If the variable is somehow set in both the GET data and the POST data, the value from the POST data will be returned and the GET value will be ignored.
- getGet() : string
- Gets a form variable from GET data, stripped of magic quotes if necessary. This function will NOT return a POST variable.
- getPathInfo() : string
- Utility function to obtain PATH_INFO information.
- getPost() : string
- Gets a form variable from POST data, stripped of magic quotes if necessary. This function will NOT return a GET variable.
- getTempFile() : string
- Creates a temporary filename for the lifetime of the script, and (optionally) registers it to be deleted at request shutdown.
- getTempFileWithExtension() : string
- Creates a temporary filename with a specific extension for the lifetime of the script, and (optionally) registers it to be deleted at request shutdown.
- nonInputVar() : mixed
- Checks to see if a value has been set by the script and not by GET, POST, or cookie input. The value being checked MUST be in the global scope.
- pformInput() : void
- Prints a hidden form input containing the session name and id.
- realPath() : string
- Returns the canonical path of the string. Like PHP's built-in realpath() except the directory need not exist on the local server.
- shutdown() : mixed
- Deletes registered files at request shutdown.
- _secureDelete() : mixed
- Securely delete the file by overwriting the data with a random string.
Properties
$patterns
A list of random patterns to use for overwriting purposes.
public
static array<string|int, mixed>
$patterns
= ["U", "\xaa", "\x92I\$", "I\$\x92", "\$\x92I", "\x00", "\x11", "\"", "3", "D", "U", "f", "w", "\x88", "\x99", "\xaa", "\xbb", "\xcc", "\xdd", "\xee", "\xff", "\x92I\$", "I\$\x92", "\$\x92I", "m\xb6\xdb", "\xb6\xdbm", "\xdbm\xb6"]
See http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html. We save the random overwrites for efficiency reasons.
$cache
Cache for extensionExists().
protected
static array<string|int, mixed>
$cache
= []
$shutdowndata
Data used to determine shutdown deletion.
protected
static array<string|int, mixed>
$shutdowndata
= ['paths' => [], 'secure' => []]
$shutdownreg
Has the shutdown method been registered?
protected
static bool
$shutdownreg
= false
Methods
createTempDir()
Creates a temporary directory in the system's temporary directory.
public
static createTempDir([bool $delete = true ][, string $temp_dir = null ]) : string
Parameters
- $delete : bool = true
-
Delete the temporary directory at the end of the request?
- $temp_dir : string = null
-
Use this temporary directory as the directory where the temporary directory will be created.
Return values
string —The pathname to the new temporary directory. Returns false if directory not created.
deleteAtShutdown()
Removes given elements at request shutdown.
public
static deleteAtShutdown(string $filename[, bool $register = true ][, bool $secure = false ]) : mixed
If called with a filename will delete that file at request shutdown; if called with a directory will remove that directory and all files in that directory at request shutdown.
If called with no arguments, return all elements to be deleted (this should only be done by Util::_deleteAtShutdown()).
The first time it is called, it initializes the array and registers Util::_deleteAtShutdown() as a shutdown function - no need to do so manually.
The second parameter allows the unregistering of previously registered elements.
Parameters
- $filename : string
-
The filename to be deleted at the end of the request.
- $register : bool = true
-
If true, then register the element for deletion, otherwise, unregister it.
- $secure : bool = false
-
If deleting file, should we securely delete the file?
Return values
mixed —extensionExists()
Caches the result of extension_loaded() calls.
public
static extensionExists(string $ext) : bool
Parameters
- $ext : string
-
The extension name.
Return values
bool —Is the extension loaded?
formInput()
Returns a hidden form input containing the session name and id.
public
static formInput([bool $append_session = false ]) : string
Parameters
- $append_session : bool = false
-
0 = only if needed, 1 = always.
Return values
string —The hidden form input, if needed/requested.
getFormData()
Gets a form variable from GET or POST data, stripped of magic quotes if necessary. If the variable is somehow set in both the GET data and the POST data, the value from the POST data will be returned and the GET value will be ignored.
public
static getFormData(string $var[, string $default = null ]) : string
Parameters
- $var : string
-
The name of the form variable to look for.
- $default : string = null
-
The value to return if the variable is not there.
Return values
string —The cleaned form variable, or $default.
getGet()
Gets a form variable from GET data, stripped of magic quotes if necessary. This function will NOT return a POST variable.
public
static getGet(string $var[, string $default = null ]) : string
Parameters
- $var : string
-
The name of the form variable to look for.
- $default : string = null
-
The value to return if the variable is not there.
Return values
string —The cleaned form variable, or $default.
getPathInfo()
Utility function to obtain PATH_INFO information.
public
static getPathInfo() : string
Return values
string —The PATH_INFO string.
getPost()
Gets a form variable from POST data, stripped of magic quotes if necessary. This function will NOT return a GET variable.
public
static getPost(string $var[, string $default = null ]) : string
Parameters
- $var : string
-
The name of the form variable to look for.
- $default : string = null
-
The value to return if the variable is not there.
Return values
string —The cleaned form variable, or $default.
getTempFile()
Creates a temporary filename for the lifetime of the script, and (optionally) registers it to be deleted at request shutdown.
public
static getTempFile([string $prefix = '' ][, bool $delete = true ][, string $dir = '' ][, bool $secure = false ]) : string
Parameters
- $prefix : string = ''
-
Prefix to make the temporary name more recognizable.
- $delete : bool = true
-
Delete the file at the end of the request?
- $dir : string = ''
-
Directory to create the temporary file in.
- $secure : bool = false
-
If deleting the file, should we securely delete the file by overwriting it with random data?
Return values
string —Returns the full path-name to the temporary file. Returns false if a temp file could not be created.
getTempFileWithExtension()
Creates a temporary filename with a specific extension for the lifetime of the script, and (optionally) registers it to be deleted at request shutdown.
public
static getTempFileWithExtension([string $extension = '.tmp' ][, string $prefix = '' ][, bool $delete = true ][, string $dir = '' ][, bool $secure = false ]) : string
Parameters
- $extension : string = '.tmp'
-
The file extension to use.
- $prefix : string = ''
-
Prefix to make the temporary name more recognizable.
- $delete : bool = true
-
Delete the file at the end of the request?
- $dir : string = ''
-
Directory to create the temporary file in.
- $secure : bool = false
-
If deleting file, should we securely delete the file by overwriting it with random data?
Return values
string —Returns the full path-name to the temporary file. Returns false if a temporary file could not be created.
nonInputVar()
Checks to see if a value has been set by the script and not by GET, POST, or cookie input. The value being checked MUST be in the global scope.
public
static nonInputVar(string $varname[, mixed $default = null ]) : mixed
Parameters
- $varname : string
-
The variable name to check.
- $default : mixed = null
-
Default value if the variable isn't present or was specified by the user. Defaults to null.
Return values
mixed —$default if the var is in user input or not present, the variable value otherwise.
pformInput()
Prints a hidden form input containing the session name and id.
public
static pformInput([bool $append_session = false ]) : void
Parameters
- $append_session : bool = false
-
0 = only if needed, 1 = always.
Return values
void —realPath()
Returns the canonical path of the string. Like PHP's built-in realpath() except the directory need not exist on the local server.
public
static realPath(string $path) : string
Algorithim loosely based on code from the Perl File::Spec::Unix module (version 1.5).
Parameters
- $path : string
-
A file path.
Return values
string —The canonicalized file path.
shutdown()
Deletes registered files at request shutdown.
public
static shutdown() : mixed
This function should never be called manually; it is registered as a shutdown function by Util::deleteAtShutdown() and called automatically at the end of the request.
Contains code from gpg_functions.php. Copyright 2002-2003 Braverock Ventures
Return values
mixed —_secureDelete()
Securely delete the file by overwriting the data with a random string.
protected
static _secureDelete(string $file[, array<string|int, mixed> $ptr = [] ]) : mixed
Parameters
- $file : string
-
Filename.
- $ptr : array<string|int, mixed> = []