PHP Class Sirius\Validation\RuleFactory

Show file Open project: siriusphp/validation Class Usage Examples

Protected Properties

Property Type Description
$errorMessages array
$labeledErrorMessages array
$validatorsMap array Validator map allows for flexibility when creating a validation rule You can use 'required' instead of 'required' for the name of the rule or 'minLength'/'minlength' instead of 'MinLength'

Public Methods

Method Description
__construct ( ) Constructor
createRule ( string | callable $name, string | array $options = null, string $messageTemplate = null, string $label = null ) : Sirius\Validation\Rule\AbstractValidator Factory method to construct a validator based on options that are used most of the times
register ( string $name, string $class, $errorMessage = '', $labeledErrorMessage = '' ) : RuleFactory Register a class to be used when creating validation rules
setMessages ( string $rule, string | null $messageWithoutLabel = null, string | null $messageWithLabel = null ) Set default error message for a rule

Protected Methods

Method Description
construcRuleByNameAndOptions ( $name, $options ) : Sirius\Validation\Rule\Callback
getSuggestedMessageTemplate ( string $name, boolean $withLabel ) : string | null Get the error message saved in the registry for a rule, where the message is with or without a the label
registerDefaultRules ( ) Set up the default rules that come with the library

Method Details

__construct() public method

Constructor
public __construct ( )

construcRuleByNameAndOptions() protected method

protected construcRuleByNameAndOptions ( $name, $options ) : Sirius\Validation\Rule\Callback
$name
$options
return Sirius\Validation\Rule\Callback

createRule() public method

Factory method to construct a validator based on options that are used most of the times
public createRule ( string | callable $name, string | array $options = null, string $messageTemplate = null, string $label = null ) : Sirius\Validation\Rule\AbstractValidator
$name string | callable name of a validator class or a callable object/function
$options string | array validator options (an array, JSON string or QUERY string)
$messageTemplate string error message template
$label string label of the form input field or model attribute
return Sirius\Validation\Rule\AbstractValidator

getSuggestedMessageTemplate() protected method

Get the error message saved in the registry for a rule, where the message is with or without a the label
protected getSuggestedMessageTemplate ( string $name, boolean $withLabel ) : string | null
$name string name of the rule
$withLabel boolean
return string | null

register() public method

Register a class to be used when creating validation rules
public register ( string $name, string $class, $errorMessage = '', $labeledErrorMessage = '' ) : RuleFactory
$name string
$class string
return RuleFactory

registerDefaultRules() protected method

Set up the default rules that come with the library
protected registerDefaultRules ( )

setMessages() public method

Set default error message for a rule
public setMessages ( string $rule, string | null $messageWithoutLabel = null, string | null $messageWithLabel = null )
$rule string
$messageWithoutLabel string | null
$messageWithLabel string | null

Property Details

$errorMessages protected property

protected array $errorMessages
return array

$labeledErrorMessages protected property

protected array $labeledErrorMessages
return array

$validatorsMap protected property

Validator map allows for flexibility when creating a validation rule You can use 'required' instead of 'required' for the name of the rule or 'minLength'/'minlength' instead of 'MinLength'
protected array $validatorsMap
return array