MakeReadable

Use this class to render model data property values to human readable values. Unreadable values are data property values which are not strings and are not suitable to immediately usable for being displayed to the end user for example ids, keys, arrays, array keys, etc.
Use case: after querying model data you may want to iterate on the model object in your template but the values set to some properties would not be suitable for displaying, the purpose of the methods in this class is to change the model properties values in-line to what they can present as human readable. Though when applied to model data, it must only be used for displaying no actions such as "add()", "update()", etc should be done in the model data.
You can also set the "__readable__" property of the model to true so the model will use this "MakeReadable" internally when data is being fetched and set to the properties (on model "next()").
Source
MakeReadable.php
Implements
IMakeReadable
Depends on
IModel , Utils

Constants

SEPARATOR = ',

Separator string, glues multi items together. Will be used if a property value is an array or object.

Static Methods

objectLists

void MakeReadable::objectLists(IModel model, string sep=self::SEPARATOR)

Renders model object list data properties, replace property values which are not readable with readable values.

Arguments

    model (IModel)
    Model object
    sep=self::SEPARATOR (string)
    When a model property value is an array the readable value must be a string, the array items will be glued together with this string

Returns

void

objects

void MakeReadable::objects(IModel model, string sep=self::SEPARATOR)

Renders model object data properties, replace property values which are not readable with readable values.

Arguments

    model (IModel)
    Model object
    sep=self::SEPARATOR (string)
    When a model property value is an array the readable value must be a string, the array items will be glued together with this string

Returns

void

property

void MakeReadable::property(IModel model, string property)

Make the value of a property of the passed model which human readable, human readable. e.g: if "options" exists in a model data property definition then change the property value as: "property-value=property-def[options][property-value]".

Arguments

    model (IModel)
    Model object
    property (string)
    Property name

Returns

void

render

void MakeReadable::render(IModel model, string sep=self::SEPARATOR)

Make all properties of the passed model which are non human readable, human readable.

Arguments

    model (IModel)
    Model object
    sep=self::SEPARATOR (string)
    When a model property value is an array the readable value must be a string, the array items will be glued together with this string

Returns

void

scalars

void MakeReadable::scalars(IModel model)

Make all scalar properties of the passed model which are non human readable, human readable. e.g: if "options" exists in a model data property definition then change the property value as: "property-value=property-def[options][property-value]".

Arguments

Returns

void

Methods

__construct

MakeReadable $obj = new MakeReadable(IModel model=null, string sep=self::SEPARATOR)

Create an "IReadable" object, if an instance of "IModel" is passed then make all of it's non human readable properties readable immediately.

Arguments

    model=null (IModel)
    Model object, if not null then all model's not human readable property values will be made readable.
    sep=self::SEPARATOR (string)
    When a model property value is an array the readable value must be a string, the array items will be glued together with this string

Returns

void