UniqueFromForeignModelValidator
extends Validator
in package
Defines a Validator object that ensures a Field's value is unique from another specified Model's field. This allows you to prevent a Field from being set to the same value as a different Model's Field.
Table of Contents
Properties
- $field_context : Field|null
- $foreign_model_field_name : string
- $foreign_model_fqn : string
- $foreign_model_name : string
- $model_context : Model|null
Methods
- __construct() : mixed
- Define this validator object by specifying the name of the foreign Model and the specific Field on the foreign Model to check for uniqueness.
- get_class_fqn() : string
- Obtains the fully qualified name of the called class.
- get_class_shortname() : string
- Obtains the shortname of the called class.
- get_classes_in_namespace() : array<string|int, mixed>
- Obtains all classes associated with this class's current namespace.
- log_error() : void
- Logs an error to the syslog.
- validate() : void
- Checks if the value passed into this Validator matches the '$foreign_model_field_name' of any existing object of the $foreign_model_name class
- set_label() : mixed
- Sets a label on the assigned $field_context if present.
Properties
$field_context
public
Field|null
$field_context
= null
The parent Model Field object that called this Validator.
$foreign_model_field_name
public
string
$foreign_model_field_name
$foreign_model_fqn
public
string
$foreign_model_fqn
$foreign_model_name
public
string
$foreign_model_name
$model_context
public
Model|null
$model_context
= null
The parent Model object that called this Validator.
Methods
__construct()
Define this validator object by specifying the name of the foreign Model and the specific Field on the foreign Model to check for uniqueness.
public
__construct(string $model, string $field) : mixed
Parameters
- $model : string
- $field : string
get_class_fqn()
Obtains the fully qualified name of the called class.
public
get_class_fqn() : string
Return values
string —The FQN for this object's class.
get_class_shortname()
Obtains the shortname of the called class.
public
get_class_shortname() : string
Return values
string —The shortname for this object's class.
get_classes_in_namespace()
Obtains all classes associated with this class's current namespace.
public
get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
- $shortnames : bool = false
Return values
array<string|int, mixed> —An array of classes currently in this object's namespace
log_error()
Logs an error to the syslog.
public
static log_error(string $message) : void
Parameters
- $message : string
-
The error message to write to the syslog
validate()
Checks if the value passed into this Validator matches the '$foreign_model_field_name' of any existing object of the $foreign_model_name class
public
validate(mixed $value[, string $field_name = '' ]) : void
Parameters
- $value : mixed
-
The value to be validated
- $field_name : string = ''
-
The name of the field that the value belongs to. This is used for error messages.
set_label()
Sets a label on the assigned $field_context if present.
protected
set_label(string $label_name) : mixed
Parameters
- $label_name : string
-
The label to assign to the Field context object