BooleanValidator

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

Extends
AbstractValidator

Validator for boolean values

Table of Contents

Properties

$acceptsEmptyValues  : bool
Specifies whether this validator accepts empty values.
$notFalseMessage  : string
$notTrueMessage  : string
$options  : array
$request  : ServerRequestInterface|null
$result  : Result
$supportedOptions  : array
This contains the supported options, their default values, types and descriptions.
$translationOptions  : array
Contains an array of property names used for translation handling of error messages.

Methods

getOptions()  : array
Returns the options of this validator
getRequest()  : ServerRequestInterface|null
Returns the request object of the validator.
isValid()  : void
Check if $value matches the expectation given to the validator.
setOptions()  : void
Receive validator options from framework.
setRequest()  : void
Sets the request object to the validator.
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
ensureFileUploadTypes()  : void
Ensures that the provided value is either an instance of UploadedFile or an ObjectStorage containing only UploadedFile instances.
getFileInfo()  : FileInfo
initializeDefaultOptions()  : void
Initialize default options.
initializeTranslationOptions()  : void
Initializes all registered translation options with custom translation options from the given options array
isEmpty()  : bool
TRUE if the given $value is NULL or an empty string ('')
translateErrorMessage()  : string
Translates an error message using LocalizationUtility::translate() method. If the translate key does not start with 'LLL:' and if no extension name is provided, the original translate key is returned.

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.

$notFalseMessage

protected string $notFalseMessage = 'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:va…
Show the full value'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:validator.boolean.notfalse'

$notTrueMessage

protected string $notTrueMessage = 'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:va…
Show the full value'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:validator.boolean.nottrue'

$request

protected ServerRequestInterface|null $request = null

$supportedOptions

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

protected array $supportedOptions = [ // The default is set to NULL here, because we need to…
Show the full value[ // The default is set to NULL here, because we need to be backward compatible here, because this // BooleanValidator is called automatically on boolean action arguments. If we would set it to TRUE, // every FALSE value for an action argument would break. // @todo with next patches: deprecate this BooleanValidator and introduce a BooleanValueValidator, like // in Flow, which won't be called on boolean action arguments. 'is' => [null, 'Boolean value', 'boolean|string|integer'], 'notTrueMessage' => [null, 'Translation key or message for not true value', 'string'], 'notFalseMessage' => [null, 'Translation key or message for not false value', 'string'], ]

$translationOptions

Contains an array of property names used for translation handling of error messages.

protected array $translationOptions = ['notTrueMessage', 'notFalseMessage']

Methods

getOptions()

Returns the options of this validator

public getOptions() : array

Return values

array

getRequest()

Returns the request object of the validator.

public getRequest() : ServerRequestInterface|null

Return values

ServerRequestInterface|null

isValid()

Check if $value matches the expectation given to the validator.

public isValid(mixed $value) : void

If it does not match, the function adds an error to the result.

Also testing for '1' (true), '0' and '' (false) because casting varies between tests and actual usage. This makes the validator loose but still keeping functionality.

Parameters

$value : mixed

setOptions()

Receive validator options from framework.

public setOptions(array $options) : void

Parameters

$options : array

setRequest()

Sets the request object to the validator.

public setRequest(ServerRequestInterface|null $request) : void

Parameters

$request : ServerRequestInterface|null

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

ensureFileUploadTypes()

Ensures that the provided value is either an instance of UploadedFile or an ObjectStorage containing only UploadedFile instances.

protected ensureFileUploadTypes(mixed $value) : void

Parameters

$value : mixed

initializeTranslationOptions()

Initializes all registered translation options with custom translation options from the given options array

protected initializeTranslationOptions(array $options) : void

Parameters

$options : array

isEmpty()

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

protected final isEmpty(mixed $value) : bool

Parameters

$value : mixed

Return values

bool

translateErrorMessage()

Translates an error message using LocalizationUtility::translate() method. If the translate key does not start with 'LLL:' and if no extension name is provided, the original translate key is returned.

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

Parameters

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

Return values

string
On this page