- Symphony 2.7.2
-
› assets
14 -
› boot
15 -
› core
24 -
› cryptography
4 -
› data-sources
6 -
› email-gateways
3 -
› events
3 -
› global
61 -
› interface
9 -
› toolkit
60 - Delegates101
- Deprecated28
Versions
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.3
- 2.7.2
- 2.7.10
- 2.7.1
- 2.7.0
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.11
- 2.6.10
- 2.6.1
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2
Options
public class General
class.general.php #10General is a utility class that offers a number miscellaneous of functions that are used throughout Symphony.
Methods
static integer array_find_available_index(
$array, $seed)
Find the next available index in an array. Works best with numeric keys. The next available index is the minimum integer such that the array does not have a mapping for that index. Uses the increment operator on the index type of the input array, whatever that may do.
Parameters
Returns
the minimum empty index into the input array.
static array array_iunique(
$array)
Filter the input array for duplicates, treating each element in the array as a string and comparing them using a case insensitive comparison function.
Parameters
Returns
a new array containing only the unique elements of the input array.
static array array_map_recursive(
$function, $array)
Function recursively apply a function to an array's values. This will not touch the keys, just the values.
Returns
a new array with all the values passed through the given $function
static array array_remove_duplicates(
$array, $ignore_case)
Filter the duplicate values from an array into a new array, optionally ignoring the case of the values (assuming they are strings?). A new array is returned, the input array is left unchanged.
Parameters
Returns
a new array containing only the unique elements of the input array.
static void array_to_xml(XMLElement $parent, $data, $validate)
Convert an array into an XML fragment and append it to an existing XML element. Any arrays contained as elements in the input array will also be recursively formatted and appended to the input XML fragment. The input XML element will be modified as a result of calling this.
Parameters
static XMLElement buildPaginationElement(
$total_entries, $total_pages, $entries_per_page, $current_page)
Construct an XML fragment that describes a pagination structure.
Parameters
Returns
the constructed XML fragment.
static boolean checkFile(
$file)
Checks that the file and its folder are readable and writable.
Deprecated
@since Symphony 2.7.0
static boolean checkFileDeletable(
$file)
Checks that the file is deletable. It first checks to see if the $file path exists and if it does, checks that is it writable.
Uses
Parameters
static boolean checkFileReadable(
$file)
Checks that the file is readable. It first checks to see if the $file path exists and if it does, checks that it is readable.
Uses
Parameters
static boolean checkFileWritable(
$file)
Checks that the file is writable. It first checks to see if the $file path exists and if it does, checks that is it writable. If the file does not exits, it checks that the directory exists and if it does, checks that it is writable.
Uses
Parameters
static void cleanArray(
$arr, $&$arr)
Strip any slashes from all array values.
Parameters
static integer convertHumanFileSizeToBytes(
$file_size)
Gets the number of bytes from 'human readable' size value. Supports
the output of General::formatFilesize
as well as reading values
from the PHP configuration. eg. 1 MB or 1M
static integer countWords(
$string)
Count the number of words in a string. Words are delimited by "spaces". The characters included in the set of "spaces" are: ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '𠀯', ' ' Any html/xml tags are first removed by strip_tags() and any included html entities are decoded. The resulting string is then split by the above set of spaces and the resulting size of the resulting array returned.
Parameters
Returns
the number of words contained in the input string.
static string createFilename(
$string, $delim)
Given a string, this will clean it for use as a filename. Preserves multi-byte characters.
Parameters
Returns
Returns created filename
static string createHandle(
$string, $max_length, $delim, $uriencode, $additional_rule_set)
Given a string, this will clean it for use as a Symphony handle. Preserves multi-byte characters.
Parameters
Returns
Returns resultant handle
static boolean|XMLElement createXMLDateObject(
$timestamp, $element, $date_format, $time_format, $namespace)
Construct an XML fragment that reflects the structure of the input timestamp.
Parameters
Returns
false if there is no XMLElement class on the system, the constructed XML element otherwise.
static boolean deleteDirectory(
$dir, $silent)
Recursively deletes all files and directories given a directory. This
function has two path. This function optionally takes a $silent
parameter,
which when false
will throw an Exception
if there is an error deleting a file
or folder.
Parameters
static boolean deleteFile(
$file, $silent)
Delete a file at a given path, silently ignoring errors depending on the value of the input variable $silent.
Uses
Parameters
Returns
true if the file is successfully unlinked, if the unlink fails and silent is set to true then an exception is thrown. if the unlink fails and silent is set to false then this returns false.
static void ensureType(
$params)
Helper to cut down on variables' type check.
Currently known types are the PHP defaults.
Uses is_XXX()
functions internally.
Parameters
static void flattenArray(
$source, $output, $path, $&$source, $&$output)
Flatten the input array. Any elements of the input array that are
themselves arrays will be removed and the contents of the removed array
inserted in its place. The keys for the inserted values will be the
concatenation of the keys in the original arrays in which it was embedded.
The elements of the path are separated by periods (.). For example,
given the following nested array structure:
array(1 =>
array('key' => 'value'),
2 =>
array('key2' => 'value2', 'key3' => 'value3')
)
will flatten to:
array('1.key' => 'value', '2.key2' => 'value2', '2.key3' => 'value3')
Parameters
static string formatFilesize(
$file_size)
Format a number of bytes in human readable format. This will append MB as appropriate for values greater than 1,0241,024, KB for values between 1,024 and 1,0241,024-1 and bytes for values between 0 and 1,024.
Parameters
Returns
the formatted number.
static array getExtension(
$file)
Extract the file extension from the input file path.
Parameters
Returns
an array with a single key 'extension' and a value of the extension of the input path.
string|boolean getMimeType(
$file)
Gets mime type of a file.
For email attachments, the mime type is very important.
Uses the PHP 5.3 function finfo_open
when available, otherwise falls
back to using a mapping of known of common mimetypes. If no matches
are found application/octet-stream
will be returned.
Returns
the mime type of the file, or false is none found
static array getPostData()
Merge $_POST
with $_FILES
to produce a flat array of the contents
of both. If there is no mergefilepost_data function defined then
such a function is created. This is necessary to overcome PHP's ability
to handle forms. This overcomes PHP's convoluted $_FILES
structure
to make it simpler to access multi-part/formdata
.
Returns
a flat array containing the flattened contents of both $_POST
and $_FILES
.
static string hash(
$input, $algorithm)
Uses SHA1
or MD5
to create a hash based on some input
This function is currently very basic, but would allow
future expansion. Salting the hash comes to mind.
Parameters
Returns
the hashed string
static boolean in_array_all(
$needles, $haystack)
Search an array for multiple values.
Parameters
Returns
true if any of the $needles
are in $haystack
, false otherwise.
static boolean in_array_multi(
$needle, $haystack)
Search a multi-dimensional array for a value.
Parameters
Returns
true if $needle
is found in $haystack
. true if $needle
== $haystack
. true if $needle
is found in any of the arrays contained within $haystack
. false otherwise.
static boolean in_iarray(
$needle, $haystack)
Test whether a value is in an array based on string comparison, ignoring the case of the values.
Parameters
Returns
true if the $needle
is in the $haystack
, false otherwise.
static int intval(
$value)
Converts a value to a positive integer. This method makes sure that the value is a valid positive integer representation before doing the cast.
Parameters
Returns
The casted integer value if the input is valid, -1 otherwise.
static string|boolean left(
$str, $num)
Extract the first $num
characters from a string.
Parameters
Returns
a string containing the last $num
characters of the input string, or false on failure.
static null|string limitWords(
$string, $maxChars, $appendHellip)
Truncate a string to a given length, respecting word boundaries. The returned
string will always be less than $maxChars
. Newlines, HTML elements and
leading or trailing spaces are removed from the string.
Parameters
Returns
if the resulting string contains only spaces then null is returned. otherwise a string that satisfies the input constraints.
static null|array listDirStructure(
$dir, $filter, $recurse, $strip_root, $exclude, $ignore_hidden)
Construct a multi-dimensional array that reflects the directory structure of a given path.
Parameters
Returns
return the array structure reflecting the input directory or null if the input directory is not actually a directory.
static null|array listStructure(
$dir, $filters, $sort, $strip_root, $exclude, $recurse, $ignore_hidden)
Construct a multi-dimensional array that reflects the directory structure of a given path grouped into directory and file keys matching any input constraints.
Parameters
Returns
return the array structure reflecting the input directory or null if the input directory is not actually a directory.
static array processFilePostData(
$filedata)
Transform a multi-dimensional array to a flat array. The input array
is expected to conform to the structure of the $_FILES
variable.
Parameters
Returns
the flattened array.
static boolean realiseDirectory(
$path, $mode, $silent)
Create all the directories as specified by the input path. If the current directory already exists, this function will return true.
Parameters
static string reverse_sanitize(
$str)
Revert any html entities to their character equivalents.
Parameters
Returns
the decoded version of the string
static string|boolean right(
$str, $num)
Extract the last $num
characters from a string.
Parameters
Returns
a string containing the last $num
characters of the input string, or false on failure.
static string sanitize(
$source)
Convert any special characters into their entity equivalents. Since Symphony 2.3, this function assumes UTF-8 and will not double encode strings.
Parameters
Returns
the encoded version of the string.
static int strlen(
$str)
Computes the length of the string.
This function will attempt to use PHP's mbstring
functions if they are available.
This function also forces utf-8 encoding.
Parameters
Returns
the string's length
static int strpos(
$haystack, $needle, $offset)
Finds position of the first occurrence of a string in a string.
This function will attempt to use PHP's mbstring
functions if they are available.
This function also forces utf-8 encoding for mbstring.
Parameters
Returns
the numeric position of the first occurrence of needle in the haystack
static string substr(
$str, $start, $length)
Creates a sub string.
This function will attempt to use PHP's mbstring
functions if they are available.
This function also forces utf-8 encoding.
Parameters
Returns
the resulting substring
static string|boolean substrmax(
$str, $val)
Extract the first $val
characters of the input string. If
$val
is larger than the length of the input string then
the original input string is returned
Parameters
Returns
the resulting string or false on failure.
static string|boolean substrmin(
$str, $val)
Extract the first $val
characters of the input string. If $val
is larger than the length of the input string then the original
input string is returned.
Parameters
Returns
the resulting string or false on failure.
static string tabsToSpaces(
$string, $spaces)
Replace the tabs with spaces in the input string.
Parameters
Returns
the resulting string.
static string unwrapCDATA(
$value)
Unwrap a value from CDATA tags to return the raw string
Parameters
Returns
The unwrapped string
static boolean uploadFile(
$dest_path, $dest_name, $tmp_name, $perm)
Move a file from the source path to the destination path and name and
set its permissions to the input permissions. This will ignore errors
in the is_uploaded_file()
, move_uploaded_file()
and chmod()
functions.
Uses
Parameters
Returns
true if the file was moved and its permissions set as required. false otherwise.
static boolean validateString(
$string, $rule)
Validate a string against a set of regular expressions.
Parameters
Returns
false if any of the rules in $rule do not match any of the strings in $string
, return true otherwise.
static string validateURL(
$url)
Check that a string is a valid URL.
Parameters
Returns
a blank string or a valid URL
static boolean validateXML(XsltProcess $xsltProcessor, $encoding, $&$errors)
$data, $errors, $isFile,
Checks an xml document for well-formedness.
Parameters
Returns
true if there are no errors in validating the XML, false otherwise.
static string wrapInCDATA(
$value)
Wrap a value in CDATA tags for XSL output of non encoded data, only if not already wrapped.
Parameters
Returns
The wrapped string
static boolean writeFile(
$file, $data, $perm, $mode, $trim)
Create a file at the input path with the (optional) input permissions
with the input content. This function will ignore errors in opening,
writing, closing and changing the permissions of the resulting file.
If opening or writing the file fail then this will return false.
This method calls General::checkFileWritable()
which properly checks
for permissions.
Uses
Parameters
Returns
true if the file is successfully opened, written to, closed and has the required permissions set. false, otherwise.