Flikore Validator
  • Api
  • Namespace
  • Class
  • Tree
  • Deprecated

Namespaces

  • Flikore
    • Validator
      • Exception
      • Interfaces
      • Intl
      • Validators

Classes

  • ValidationChoice
  • ValidationCombo
  • ValidationKey
  • ValidationSet
  • ValidationValue
  • Validator

Class ValidationSet

A set of validation rules to be checked at the same input set.

Flikore\Validator\ValidationSet implements Flikore\Validator\Interfaces\IValidator
Namespace: Flikore\Validator
Package: Flikore\Validator
Copyright: (c) 2014, George Marques
License: MIT
Author: George Marques <george at georgemarques.com.br>
Version: 0.5.2
Since: 0.1
Located at Flikore/Validator/ValidationSet.php

Methods summary

public
# __construct( array $rules = array(), array $labels = array() )

Creates a new validation set.

Creates a new validation set.

Parameters

$rules
array
$rules An array of rules with the key being the name of the attribute and the value being a Validator instance.
$labels
array
$labels The association of name => label to show in error messages.
public
# addRule( string $name, Flikore\Validator\Validator $rule, string $label = null )

Adds a new rule for a given property or key name.

Adds a new rule for a given property or key name.

Parameters

$name
string
$name The name of the key or property.
$rule
Flikore\Validator\Validator
$rule The validation rule.
$label
string
$label The label to be shown in the error message (intead of the name).
public
# addRules( string $name, Flikore\Validator\Validator[] $rules, string $label = null )

Adds a new set rules for a given property or key name.

Adds a new set rules for a given property or key name.

Parameters

$name
string
$name The name of the key or property.
$rules
Flikore\Validator\Validator[]
$rules The array of rules.
$label
string
$label The label to be shown in the error message (intead of the name).
public array
# getRulesFor( string $key )

Gets the set of rules prepared for a given key.

Gets the set of rules prepared for a given key.

Parameters

$key
string
$key The key to get.

Returns

array
The array with the rules (may be emtpy).
public array
# getAllRules( )

Gets all the rules in this set.

Gets all the rules in this set.

Returns

array
The collection of rules by fields.
public boolean
# validate( mixed $object, array $fields = null )

Checks if the object or array passes all the validation tests.

Checks if the object or array passes all the validation tests.

Parameters

$object
mixed
$object The object or array to test.
$fields
array
$fields A list of fields to check, ignoring the others.

Returns

boolean
Whether it passes the tests or not.

Throws

InvalidArgumentException
If the fields parameter is not string nor array.
OutOfBoundsException
If there's a rule for a key that is not set.

Implementation of

Flikore\Validator\Interfaces\IValidator::validate()
public
# assert( mixed $object, array $fields = null )

Tests whether the given object or array pass all the given rules.

Tests whether the given object or array pass all the given rules.

Parameters

$object
mixed
$object The object or array to test.
$fields
array
$fields A list of fields to check, ignoring the others.

Throws

Flikore\Validator\Exception\ValidatorException
If there's a validation error.
OutOfBoundsException
If there's a rule for a key that is not set.
InvalidArgumentException
If the fields parameter is not string nor array.

Implementation of

Flikore\Validator\Interfaces\IValidator::assert()
public
# addKeyValue( string $key, string $value )

Adds a new key-value pair to be replaced by the templating engine. This does not check if it's replacing a specific validator value.

Adds a new key-value pair to be replaced by the templating engine. This does not check if it's replacing a specific validator value.

Parameters

$key
string
$key The key to replace (in the template as "%key%")
$value
string
$value The value to be inserted instead of the key.

Implementation of

Flikore\Validator\Interfaces\IValidator::addKeyValue()
protected mixed
# getKeyValue( mixed $object, string $key )

Gets a value for a given key in an object or array.

Gets a value for a given key in an object or array.

Parameters

$object
mixed
$object The object or array.
$key
string
$key The name of the key or property.

Returns

mixed
The value.

Throws

OutOfBoundsException
protected
# getRealValidator( Flikore\Validator\ValidationValue $validationValue, mixed $object )

Generates a validator object based on a ValidationValue.

Generates a validator object based on a ValidationValue.

Parameters

$validationValue
Flikore\Validator\ValidationValue
$validationValue The value to use as generator.
$object
mixed
$object The object or array being validated.
protected
# updateKeyValues( )

Updates the inner key-value pairs to reflect this object's values.

Updates the inner key-value pairs to reflect this object's values.

protected
# updateSingleKeyValue( Flikore\Validator\Interfaces\IValidator $rule )

Updates a single validator to have the same key-values added to the set.

Updates a single validator to have the same key-values added to the set.

Parameters

$rule
Flikore\Validator\Interfaces\IValidator
$rule The rule to update
protected
# getFields( string|array $fields )

Gets the fields from the input. As function to avoid repeat on validate and assert.

Gets the fields from the input. As function to avoid repeat on validate and assert.

Parameters

$fields
string|array
$fields The input fields.

Throws

InvalidArgumentException
If the fields parameter is not string nor array.

Magic methods summary

Properties summary

protected Validator[][] $validators
#

An array of validation objects.

An array of validation objects.

protected array $values
#

Stores the key-value pairs for the inner validators.

Stores the key-value pairs for the inner validators.

Flikore Validator API documentation generated by ApiGen 2.8.0