GenericObjectValidator

final class \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator

Extends
AbstractGenericObjectValidator

A generic object validator which allows for specifying property validators.

This is used as default model validator.

Table of Contents

Properties

$acceptsEmptyValues  : bool
Specifies whether this validator accepts empty values.
$options  : array
$propertyValidators  : array<string, SplObjectStorage<string|int, ValidatorInterface>>
$result  : Result
$supportedOptions  : array
This contains the supported options, their default values, types and descriptions.
$validatedInstancesContainer  : SplObjectStorage

Methods

addPropertyValidator()  : void
Adds the given validator for validation of the specified property.
canValidate()  : bool
Checks the given object can be validated by the validator implementation
getOptions()  : array
Returns the options of this validator
getPropertyValidators()  : ($propertyName is null ? array> : SplObjectStorage)
Returns all property validators - or only validators of the specified property
setOptions()  : void
Receive validator options from framework.
setValidatedInstancesContainer()  : void
Allows to set a container to keep track of validated instances.
validate()  : Result
Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.
addError()  : void
Creates a new validation error object and adds it to $this->result
addErrorForProperty()  : void
Creates a new validation error object for a property and adds it to the proper sub result of $this->result
checkProperty()  : void
Checks if the specified property of the given object is valid, and adds found errors to the $messages object.
getPropertyValue()  : mixed
Load the property value to be used for validation.
initializeDefaultOptions()  : void
Initialize default options.
isEmpty()  : bool
TRUE if the given $value is NULL or an empty string ('')
isValid()  : void
Checks if the given value is valid according to the property validators.
isValidatedAlready()  : bool
markInstanceAsValidated()  : void
translateErrorMessage()  : string
Wrap static call to LocalizationUtility to simplify unit testing.

Properties

$acceptsEmptyValues

Specifies whether this validator accepts empty values.

protected bool $acceptsEmptyValues = true

If this is TRUE, the validators isValid() method is not called in case of an empty value Note: A value is considered empty if it is NULL or an empty string! By default, all validators except for NotEmpty and the Composite Validators accept empty values.

$supportedOptions

This contains the supported options, their default values, types and descriptions.

protected array $supportedOptions = []

$validatedInstancesContainer

protected SplObjectStorage $validatedInstancesContainer

Methods

addPropertyValidator()

Adds the given validator for validation of the specified property.

public addPropertyValidator(string $propertyName, ValidatorInterface $validator) : void

Parameters

$propertyName : string
$validator : ValidatorInterface

canValidate()

Checks the given object can be validated by the validator implementation

public canValidate(mixed $object) : bool

Parameters

$object : mixed

Return values

bool

getOptions()

Returns the options of this validator

public getOptions() : array

Return values

array

getPropertyValidators()

Returns all property validators - or only validators of the specified property

public getPropertyValidators([string|null $propertyName = null ]) : ($propertyName is null ? array> : SplObjectStorage)

Parameters

$propertyName : string|null = null

Return values

($propertyName is null ? array> : SplObjectStorage)

setOptions()

Receive validator options from framework.

public setOptions(array $options) : void

Parameters

$options : array

setValidatedInstancesContainer()

Allows to set a container to keep track of validated instances.

public setValidatedInstancesContainer(SplObjectStorage $validatedInstancesContainer) : void

Parameters

$validatedInstancesContainer : SplObjectStorage

A container to keep track of validated instances

validate()

Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.

public validate(mixed $value) : Result

Parameters

$value : mixed

The value that should be validated

Return values

Result

addError()

Creates a new validation error object and adds it to $this->result

protected addError(string $message, int $code[, array $arguments = [] ][, string $title = '' ]) : void

Parameters

$message : string

The error message

$code : int

The error code (a unix timestamp)

$arguments : array = []

Arguments to be replaced in message

$title : string = ''

title of the error

addErrorForProperty()

Creates a new validation error object for a property and adds it to the proper sub result of $this->result

protected addErrorForProperty(string|array $propertyPath, string $message, int $code[, array $arguments = [] ][, string $title = '' ]) : void

Parameters

$propertyPath : string|array

The property path (string or array)

$message : string

The error message

$code : int

The error code (a unix timestamp)

$arguments : array = []

Arguments to be replaced in message

$title : string = ''

Title of the error

checkProperty()

Checks if the specified property of the given object is valid, and adds found errors to the $messages object.

protected checkProperty(mixed $value, Traversable $validators, string $propertyName) : void

Parameters

$value : mixed
$validators : Traversable
$propertyName : string

getPropertyValue()

Load the property value to be used for validation.

protected getPropertyValue(object $object, string $propertyName) : mixed

In case the object is a doctrine proxy, we need to load the real instance first.

Parameters

$object : object
$propertyName : string

isEmpty()

TRUE if the given $value is NULL or an empty string ('')

protected final isEmpty(mixed $value) : bool

Parameters

$value : mixed

Return values

bool

isValid()

Checks if the given value is valid according to the property validators.

protected isValid(mixed $object) : void

Parameters

$object : mixed

isValidatedAlready()

protected isValidatedAlready(object $object) : bool

Parameters

$object : object

Return values

bool

markInstanceAsValidated()

protected markInstanceAsValidated(object $object) : void

Parameters

$object : object

translateErrorMessage()

Wrap static call to LocalizationUtility to simplify unit testing.

protected translateErrorMessage(string $translateKey, string $extensionName[, array $arguments = [] ]) : string

Parameters

$translateKey : string
$extensionName : string
$arguments : array = []

Return values

string
On this page