Utils

Contains general uncategorized static methods mostly used by other Artaengine classes.
Source
Utils.php
Implements
IUtils
Depends on
IModel , Render
Since
1.0.0

Static Methods

array2string

string Utils::array2string(array array, array configs=null, bool first=true)

Flatten an array into a string for display purposes.

Arguments

    array (array)
    Array to render
    configs=null (array)
    Settings
    {
        bool   php      : true
            true=return string to be a valid PHP source code
            false=return to be psudo list and dictionary string,
        number id       : 1
            indent multiplier,
        bool   model    : false
            true=consider the "array" as a IModel data property definition,
        array  consts   : []
            a list of string values as [val]
            if a value anywhere inside the array matches with an item of
            this list, it will not be treated as a string,
        array  constk   : []
            a list of string values as [key] -
            if a key anywhere inside the array matches with an item of
            this list, it will not be treated as a string,
        bool   nokey    : false
            true=if array keys are numeric dont put them in place of keys
            e.g. {0:a, 1:b, c:} ===> [a, b, c],
    }
    
    first=true (bool)
    For internal use

Returns

string
The flattened array

arrayUpdate

void Utils::arrayUpdate(array base, array source)

Updates base array with source array. The new elements of source will be added to base, the non array elements of base will be updated with the elements of source if they exists in source and have the same key. Elements with the same key that are array in base but not array in source will be updated with the source value. The elements with the same key that are array in both base and source will be updated recursively in the same way.

Arguments

    base (array)
    reference to base array which will be updated
    source (array)
    source array

Returns

void

getBrowserDictionary

array Utils::getBrowserDictionary()

Get browser dictionary (front-end resource dictionary).

Since
Artaengine 1.2.2

Returns

array
[{js dic}, {css dic}, {template dic}]

getCallStaticMethod

mixed Utils::getCallStaticMethod(string source)

Get class static method or static property value by string.

Since
Artaengine 1.2.2

Arguments

    source (string)
    "Class::method" or "Class::property"

Returns

mixed
The returned value of "Class::method()" or "Class::property"

getModelPath

IModel Utils::getModelPath(IModel model, string path)

Traverse/crawl a path of objects in the model and returns the last node.

Since
Artaengine 1.2.2

Arguments

    model (IModel)
    Model object to start the traverse from
    path (string)
    Path showing model objects, last node may be a method

Returns

IModel
Last model object found

getModelPathData

mixed Utils::getModelPathData(IModel model, string path, bool render=true, array &def=array)

Traverse/crawl a path of objects in the model and return the data found on the last node.

Arguments

    model (IModel)
    Model object to start the traverse from
    path (string)
    Path showing model objects, last node may be a method last node may be a method
    render=true (bool)
    true=apply "Render::list2Html()" on result
    &def=array (array)
    Will be set to last Model object definition

Returns

mixed
Whatever is found on the last node

isList

bool Utils::isList(array array)

Is an array a list or a dictionary, list means keys start from 0 and are numeric and sequential.

Since
Artaengine 1.1.0

Arguments

    array (array)
    Array to be checked

Returns

bool
true=is list

mapModelPropertyOptions

void Utils::mapModelPropertyOptions(array | string &data, array def)

If a model data property has options, this function will replace the option key which is set to the property with the option's value. This is to make all property values of a model human readable (but not actionable).

Arguments

    &data (array | string)
    Reference to model property data to render
    def (array)
    Model property definition

Returns

void

pluralize

string Utils::pluralize(string word)

Pluralize an English word. used methods from http://blog.eval.ca/2007/03/03/php-pluralize-method/ and http://kuwamoto.org

Arguments

    word (string)
    Word to be pluralized

Returns

string
Pluralized word

rmdir

void Utils::rmdir(string dir)

Remove directory recursively.

Arguments

    dir (string)
    directory to remove

Returns

void

space

string Utils::space(int n)

Return a string containing n space characters.

Arguments

    n (int)
    Number of space characters

Returns

string
String with n space characters

str2typ

const Utils::str2typ(string type=null)

Convert "T::TYPE_CONST" (Artaengine data type) string to const. This ambiguous is used for editing PHP model files.

Arguments

    type=null (string)
    "T::TYPE_CONST" (Artaengine data type) string

Returns

const
"T::TYPE_CONST" (Artaengine data type)

translateArray

array Utils::translateArray(&aReference to)

gettext an array.

Arguments

    to (&aReference)
    the array

Returns

array
Translated

typ2str

string Utils::typ2str(string type=null)

Convert "T::TYPE_CONST" (Artaengine data type) const to string. This ambiguous is used for editing PHP model files.

Arguments

    type=null (string)
    "T::TYPE_CONST" (Artaengine data type) string

Returns

string
"T::TYPE_CONST" (Artaengine data type) as string