zObject

A zObject is basicaly an associative array (map) with public accessors accepting keys in path format, that is, nested keys delimited by a slash. That makes it very easy to costruct and access tree-like structures. This is, in fact, happening all over the place in zoglair.

zObject publishes quite a few static path handling funcs and other helpers. Although not all of them are needed by its accessors, they are included for the sake of completeness.

Parent Class
none
Public Methods (19)
__construct, add_info, array2str, array2xml, get_arg, get_info, get_xml, inc_info, Instance, path_base_dir, path_base_dir_cut, path_change_ext, path_change_name, path_end_slash_cut, path_ext, path_ext_cut, set_info, set_xml, xml2array
Protected Methods
none

void __construct(array $INFO, boolean $singleton=FALSE)‎

It should be noted that system zoglair classes must be instantiated via its factory method zoglair::load_plugin() and not directly. The factory does a lot more than simply calling “new”. The $singleton default argument (and the surrounding mechanism) is kind of a hack, but unfortunately cannot be done in an academic fashion. The constructor has to be inheritable and PHP does not permit it unless it is public.

Parameters
• Initial object properties (use a map - not vector!)
• Is this a singleton? (use Instance() if TRUE)
Returns
void

void add_info(string $info, mixed $value, boolean $unique=TRUE)‎

Helper function which combines get_info() and set_info() to add (append) a value in a property of type array (vector).

Parameters
• The name (or path) of the requested property, eg: “name”, “name1/.../nameN”, etc
• The value to be added (usually a string)
• Set unique values? If TRUE (the default), then the value will not be added if already exists.
Returns
void

See also get_info(), set_info(), inc_info().

string array2str(array $A, integer $level=0, integer $maxlen=0)‎static

Converts an array to a human readable *.ini-like string. This function is recursive, so it can handle nested keys for tree-like maps, such as a zObject's properties. The array is sorted (by key order) before processing.

Parameters
• The array to convert
• Starting indentation level
• Max key padding length (auto calculated if 0)
Returns
The array coverted

string array2xml(array $A, integer $level=0)‎static

Converts an array to a human readable *.xml-like string. This function is recursive, so it can handle nested keys for tree-like maps, such as a zObject's properties.

Parameters
• The array to convert
• Starting indentation level
Returns
The array coverted

See also xml2array().

mixed get_arg(mixed $ARGS, string $key, mixed $default='')‎static

Safeguard for accessing array keys. Use this instead of testing with isset() or the error suppress operator “@”.

Parameters
• An associative array (map) or a string in URL query format
• A key whose value will be returned
• A default value for unset keys
Returns
The value of the key requested

mixed get_info(string $info, mixed $default=NULL)‎

A universal, high usage frequency, object accessor. Used for getting the value of any object property (existing or not). Remember that properties are stored in a tree map, so the info passed can be a path.

Parameters
• The name (or path) of the requested property, eg: “name”, “name1/.../nameN”, etc
• A default value for unset properties
Returns
The value of the property requested

See also set_info(), add_info(), inc_info().

string get_xml(string $root=zDataBase::Z_TBL_NAME_ADDON)‎

Return the object's properties in XML format.

Parameters
The name to be used for the root XML element
Returns
A dump of the object's properties, as generated by array2xml()

See also set_xml().

mixed inc_info(string $info, mixed $value=1)‎

Helper function which combines get_info() and set_info() to increment a property's value. Useful for counters, run totals, etc.

Parameters
• The name (or path) of the requested property, eg: “name”, “name1/.../nameN”, etc
• The value to be added (usually numeric)
Returns
The new (updated) value

See also get_info(), set_info(), add_info().

void Instance(array $INFO)‎static

A smart, polymorphic, method that gives the singleton capability to any derivative class. So, the class tree is kept plain and easy! No need to call it explicitly: zoglair::load_plugin() calls it on a need-to-use basis.

Parameters
Initial object properties (as in its constructor)
Returns
void

string path_base_dir(string $path, string $default='')‎static

Extracts the base dir (if exists) from a path. For example, “dir1/.../dirN/” will become “dir1”.

Parameters
• A path
• A default, in case there is no slash in the path
Returns
The base dir or the default value

string path_base_dir_cut(string $path)‎static

Cuts the base dir (if exists) from a path. For example, “dir1/.../dirN/” will become “.../dirN/”.

Parameters
A path
Returns
The path unaltered or with its base dir removed

string path_change_ext(string $path, string $ext)‎static

Changes the file extension of a path, existing or not. For example, “dir1/.../name.ext” will become “dir1/.../name.newext”.

Parameters
• A path
• The new extension
Returns
The path altered

string path_change_name(string $path, string $name)‎static

Changes the file name of a path, existing or not. For example, “dir1/.../name.ext” will become “dir1/.../newname.ext”.

Parameters
• A path
• The new name
Returns
The path altered

string path_end_slash_cut(string $path)‎static

Cuts the trailing slash (if exists) from a path. For example, “dir1/.../dirN/” will become “dir1/.../dirN”.

Parameters
A path
Returns
The path unaltered or with its trailing slash removed

string path_ext(string $path, string $default='')‎static

Extracts the file extension (if exists) from a path, without the dot. For example, “dir1/.../name.ext” will become “ext”.

Parameters
• A path
• A default, in case there is no extension in the path
Returns
The extension or the default value

string path_ext_cut(string $path)‎static

Cuts the file extension (if exists) from a path, including the dot. For example, “dir1/.../name.ext” will become “dir1/.../name”.

Parameters
A path
Returns
The path unaltered or with its extension removed

void set_info(string $info, mixed $value)‎

A universal, high usage frequency, object mutator. Used for setting the value of any object property (existing or not). Remember that properties are stored in a tree map, so the info passed can be a path.

Parameters
• The name (or path) of the requested property, eg: “name”, “name1/.../nameN”, etc
• The property's value
Returns
void

See also get_info(), add_info(), inc_info().

void set_xml(string $xml)‎

Recreates object's properties according to the $xml contents. This must have been previously generated by get_xml().

Parameters
The new properties in xml format
Returns
void

See also get_xml().

array xml2array(string $xml)‎static

Converts an *.xml-like string to an array (map). This is the reverse of array2xml() and basically used in set_xml() for unserializing an object that has been previously serialized by get_xml().

Parameters
The string to be converted
Returns
The resulting array

See also array2xml().

(C) Nick B. Cassos - All Rights Reserved
powered by zoglair
page generated in 130ms (11 queries, 11ms)