Wrapper for CFPropertyList to handle low level iteration.
Author: | Andrew Madden <andrewmadden@catalyst-au.net> |
Copyright: | 2019 Catalyst IT |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 404 lines (17 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
property_list:: (15 methods):
__construct()
add_element_to_root()
get_element_value()
update_element_value()
update_element_array()
delete_element()
set_or_update_value()
to_xml()
to_json()
prepare_plist_for_json_encoding()
plist_map()
array_sort()
array_remove_empty_arrays()
array_serialize_cftypes()
is_associative_array()
Class: property_list - X-Ref
Wrapper for CFPropertyList to handle low level iteration.__construct(string $xml = '') X-Ref |
property_list constructor. param: string $xml A Plist XML string. |
add_element_to_root(string $key, CFType $element) X-Ref |
Add a new element to the root dictionary element. param: string $key Key to assign to new element. param: CFType $element The new element. May be a collection such as an array. |
get_element_value(string $key) X-Ref |
Get value of element identified by key. param: string $key Key of element. return: mixed Value of element found, or null if none found. |
update_element_value(string $key, $value) X-Ref |
Update the value of any element with matching key. Only allow string, number and boolean elements to be updated. param: string $key Key of element to update. param: mixed $value Value to update element with. |
update_element_array(string $key, array $value) X-Ref |
Update the array of any dict or array element with matching key. Will replace array. param: string $key Key of element to update. param: array $value Array to update element with. |
delete_element(string $key) X-Ref |
Delete any element with a matching key. param: string $key Key of element to delete. |
set_or_update_value(string $key, CFType $input) X-Ref |
Helper function to either set or update a CF type value to the plist. param: string $key param: CFType $input |
to_xml() X-Ref |
Convert the PList to XML. return: string XML ready for creating an XML file. |
to_json() X-Ref |
Return a JSON representation of the PList. The JSON is constructed to be used to generate a SEB Config Key. See the developer documention for SEB for more information on the requirements on generating a SEB Config Key. https://safeexambrowser.org/developer/seb-config-key.html 1. Don't add any whitespace or line formatting to the SEB-JSON string. 2. Don't add character escaping (also backshlashes "\" as found in URL filter rules should not be escaped). 3. All <dict> elements from the plist XML must be ordered (alphabetically sorted) by their key names. Use a recursive method to apply ordering also to nested dictionaries contained in the root-level dictionary and in arrays. Use non-localized (culture invariant), non-ASCII value based case insensitive ordering. For example the key <key>allowWlan</key> comes before <key>allowWLAN</key>. Cocoa/Obj-C and .NET/C# usually use this case insensitive ordering as default, but PHP for example doesn't. 4. Remove empty <dict> elements (key/value). Current versions of SEB clients should anyways not generate empty dictionaries, but this was possible with outdated versions. If config files have been generated that time, such elements might still be around. 5. All string elements must be UTF8 encoded. 6. Base16 strings should use lower-case a-f characters, even though this isn't relevant in the current implementation of the Config Key calculation. 7. <data> plist XML elements must be converted to Base64 strings. 8. <date> plist XML elements must be converted to ISO 8601 formatted strings. return: string A json encoded string. |
prepare_plist_for_json_encoding($root) X-Ref |
Recursively convert PList date values from unix to iso 8601 format, and ensure strings are UTF 8 encoded. This will mutate the PList. param: \Iterator $root The root element of the PList. Must be a dictionary or array. |
plist_map(callable $callback, \Iterator $root, bool $recursive = true) X-Ref |
Iterate through the PList elements, and call the callback on each. param: callable $callback A callback function called for every element. param: \Iterator $root The root element of the PList. Must be a dictionary or array. param: bool $recursive Whether the function should traverse dicts and arrays recursively. |
array_sort(array $array) X-Ref |
Recursively sort array alphabetically by key. param: array $array Top level array to process. return: array Processed array. |
array_remove_empty_arrays(array $array) X-Ref |
Recursively remove empty arrays. param: array $array Top level array to process. return: array Processed array. |
array_serialize_cftypes(array $array) X-Ref |
If an array contains CFType objects, wrap array in a CFDictionary to allow recursive serialization of data into a standard PHP array. param: array $array Array containing CFType objects. return: array Standard PHP array. |
is_associative_array(array $array) X-Ref |
Check if an array is associative or sequential. param: array $array Array to check. return: bool False if not associative. |