IBinder

Binds array data to model data or model data into an array. The Artaengine "Form" class uses this interface to pull out the submitted form data and put the data into a model object. The "Form" class assignes a random token key and value to each form it renders and stores the token in session, by default when you use the "$form.bind()" or "Form::b()" to fill a model object with the submitted data validity of the token will be verified but if you use "Binder::push()" to fill a model object with the submitted data by default the token is not checked.
Source
IBinder.php
Implementations
Binder

Static Methods

pull

array IBinder::pull(IModel model, configs=null array)

Fill an array with model data. If a model property value is null then the array key will be set to "Binder::DEFAULT_VALUE" unless override by "default" and "default_val" keys. For model properties which are assigned to an object the sub-object values will be pulled recursively.

Arguments

    model (IModel)
    Model object as data source
    array (configs=null)
    Parameters {prefix:, postfix:, default:}
    {
        string prefix :
            in source key names; this will be added as a prefix to model's
            property names,
        string postfix :
            in source key names; this will be added as a postfix to model's
            property names,
        bool   default : true
            true=when a model property value is null then set the key which
            represents that property in the return array to default_val or
            Binder::DEFAULT_VALUE false=don't add a key to the return array
            for properties set to null,
        mixed  default_val : Binder::DEFAULT_VALUE
            if default=true and property value=null set a key in return array
            to this value,
        string full : false
            for the model properties that are an instance of IModel
            false=put the model's key(model's primary key) value in the
            return array true=put an array of model's data
            (use Binder::pull() recursively),
    }
    

Returns

array
Array of model data {prefix-property-name-postfix: data,}

push

bool IBinder::push(
    IModel model,
    object | array | string | const source=post,
    array configs=null
)

Fill model data properties with data from an array or object or PHP request array. The source array keys or object property names may be as "PREFIX-model-property-name-POSTFIX". By default the model properties which are already set to a value will only be overwritten if a keys represents them in source with values not null. To force model properties to be saved NULL in database add a "__nulls" key to the source and set a list of property names or a string of property names separated by coma.

Arguments

    model (IModel)
    The model object to be filled with source data
    source=post (object | array | string | const)
    array=data source array to set it's data to model's properties, string=PHP request array name to set it's data to model's properties: 'post' or 'get' or 'cookie' or 'session' or 'request', const=request array constant: INPUT_GET or INPUT_POST or INPUT_COOKIE or INPUT_SESSION or INPUT_REQUEST, object=data source to set it's properties data to model's properties.
    configs=null (array)
    Configs to change default behavior
    {
        string prefix :
            to compensate matching keys with model's property name; when keys
            are not exactly the same as the model's property names and have an
            extra prefix,
        string postfix :
            to compensate matching keys with model's property name; when keys
            are not exactly the same as the model's property names and have an
            extra postfix,
        bool   token : false
            true=protect against XSRF attracts. proceed only if a token key exists
            in the source and session and matches. This is what will be checked:
            "$_SESSION[Arta.Form][token-key] === $source[token-key]"
            when a forms is created by an Artaengine form generator a such token
            is dded to both the form and session,
        bool   default : false
            when no key in source matches with a model property name then if this
            is false=leave the property value as it is (don't do anything)
            true=set the property value to default_val or Binder::DEFAULT_VALUE,
        mixed  default_val : Binder::DEFAULT_VALUE
            if default=true and property value=null set the property value to this,
        string check :
            proceed only if this key or prefix-key-postfix exists in the source,
    }
    

Returns

bool
true=model was successfully filled, false=source is invalid or token (if must check) is invalid or configs "check" (if specified) does not exists in source