LengthValidator
extends Validator
in package
Defines a Validator that checks if a given value is within a specified length range. This can be used to check both array and string lengths.
Table of Contents
Properties
- $field_context : Field|null
- $maximum : int
- $minimum : int
- $model_context : Model|null
- $__log_level : int
Methods
- __construct() : mixed
- Assigns the threshold for length validation.
- 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() : void
- Writes a log entry to the applicable log file
- validate() : void
- Runs the necessary validation against a specified value. This method is intended to be overridden by a child class to add the desired validation steps.
- 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.
$maximum
public
int
$maximum
$minimum
public
int
$minimum
$model_context
public
Model|null
$model_context
= null
The parent Model object that called this Validator.
$__log_level
private
static int
$__log_level
Methods
__construct()
Assigns the threshold for length validation.
public
__construct(int $minimum, int $maximum) : mixed
Parameters
- $minimum : int
-
The minimum length allowed by the value.
- $maximum : int
-
The maximum length allowed by the value.
get_class_fqn()
Obtains the fully qualified name of the called class.
public
static 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
static 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()
Writes a log entry to the applicable log file
public
static log(int $level, string $message[, string $logfile = 'restapi' ]) : void
Parameters
- $level : int
-
The log level to write. This should be one of the LOG_* constants defined by syslog.
- $message : string
-
The message to write to the log file.
- $logfile : string = 'restapi'
-
The log file to write to. This must be a valid logging facility defined in the package's info.xml file.
validate()
Runs the necessary validation against a specified value. This method is intended to be overridden by a child class to add the desired validation steps.
public
validate(mixed $value[, string $field_name = '' ]) : void
Parameters
- $value : mixed
-
The value to validate.
- $field_name : string = ''
-
The field name of the value being validated. This is used for error messages.
Tags
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