COAR Notify
 
Loading...
Searching...
No Matches
coarnotify\validate\Validator Class Reference

Public Member Functions

 __construct (array $rules)
 
 get ($property, $context=null)
 
 rules ()
 
 addRules (array $rules)
 

Detailed Description

A wrapper around a set oaf validation rules which can be used to select the appropriate validator in a given context.

The validation rules are structured as follows:

{
"<property>": {
"default": default_validator_function
"context": {
"<context>": {
"default": default_validator_function
}
}
}
}

Here the <property> key is the name of the property being validated, which may be a string (the property name) or a tuple of strings (the property name and the namespace for the property name).

If a context is provided, then if the top level property is being validated, and it appears inside a field present in the context then the default validator at the top level is overridden by the default validator in the context.

For example, consider the following rules:

{
"context": {
"default": Validators::oneOf([
ActivityStreamsTypes::SERVICE,
ActivityStreamsTypes::APPLICATION
])
}
}
}
}
const ACTOR
Definition Properties.php:32
const TYPE
Definition Properties.php:20
static oneOf(array $values)
Definition Validators.php:143
static typeChecker($obj, $value)
Definition Validators.php:214

This tells us that the TYPE property should be validated with typeChecker by default. But if we are looking at that TYPE property inside an ACTOR object, then instead we should use validate.one_of.

When the get method is called, the context parameter can be used to specify the context in which the property is being validated.

Constructor & Destructor Documentation

◆ __construct()

coarnotify\validate\Validator::__construct ( array $rules)

Create a new validator with the given rules

Parameters
array$rulesThe rules to use for validation

Member Function Documentation

◆ addRules()

coarnotify\validate\Validator::addRules ( array $rules)

Add new rules to the existing ruleset

Parameters
array$rules

◆ get()

coarnotify\validate\Validator::get ( $property,
$context = null )

Get the validation function for the given property in the given context

Parameters
string | array$propertyThe property to get the validation function for
string | array | null$contextThe context in which the property is being validated
Returns
callable|null A function which can be used to validate the property

◆ rules()

coarnotify\validate\Validator::rules ( )

The ruleset for this validator

Returns
array

The documentation for this class was generated from the following file: