Valdi\RulesBuilder

class RulesBuilder

To ease the building of the rules array.

property rules

protected

Holds the rules under construction.

create()

Creates and returns an instance.

Returns:RulesBuilder the new instance
__construct()

Constructor.

addFieldRule($field, $rule)

Adds a rule for a field to the set. This function takes a variable amount of parameters in order to cover the rule parameters. Example for a rule without parameter: addFieldRule(‘myField’, ‘required’) Example for a rule with two parameters: addFieldRule(‘myField’, ‘between’, 3, 7)

Parameters:
  • $field (string) – the field for the rule
  • $rule (string) – the rule to add
Returns:

RulesBuilder the instance of the called RulesBuilder in order to chain the rules creation

addRule($rule)

Adds a rule to the set. This function takes a variable amount of parameters in order to cover the rule parameters. Example for a rule without parameter: addRule(‘required’) Example for a rule with two parameters: addRule(‘between’, 3, 7)

Parameters:
  • $rule (string) – the rule to add
Returns:

RulesBuilder the instance of the called RulesBuilder in order to chain the rules creation

build()

Gets the created rules. Afterwards, the RulesBuilder is emptied and ready to be used again.

Returns:array the created rules