IsJsonString
extends AbstractValidator
in package
Tags
Table of Contents
Constants
- ALLOW_ALL = 0b11111
- ALLOW_ARRAY = 0b1000
- ALLOW_BOOL = 0b100
- ALLOW_FLOAT = 0b10
- ALLOW_INT = 0b1
- ALLOW_OBJECT = 0b10000
- ERROR_INVALID_JSON = 'errorInvalidJson'
- ERROR_MAX_DEPTH_EXCEEDED = 'errorMaxDepthExceeded'
- ERROR_NOT_STRING = 'errorNotString'
- ERROR_TYPE_NOT_ALLOWED = 'errorTypeNotAllowed'
Properties
- $messageTemplates : array<string, string>
- $messageVariables : array<string, mixed>
- $options : array<string, mixed>
- $abstractOptions : AbstractOptions|array<string, mixed>
- $allow : int
- $defaultTranslator : TranslatorInterface
- Default translation object for all validate objects
- $defaultTranslatorTextDomain : string
- Default text domain to be used with translator
- $maxDepth : positive-int
- $messageLength : int
- Limits the maximum returned length of an error message
- $messageTemplates : mixed
- $messageVariables : array<string, string>
- $type : string|null
- $value : mixed
- The value to be validated
Methods
- __construct() : mixed
- Abstract constructor for all validators A validator should accept following parameters: - nothing f.e. Validator() - one or multiple scalar values f.e. Validator($first, $second, $third) - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third')) - an instance of Traversable f.e. Validator($config_instance)
- __get() : mixed
- Magic function returns the value of the requested property, if and only if it is the value or a message variable.
- __invoke() : bool
- Invoke as command
- getDefaultTranslator() : TranslatorInterface|null
- Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() : string
- Get default translation text domain for all validate objects
- getMessageLength() : int
- Returns the maximum allowed message length
- getMessages() : array<string, string>
- Returns array of validation failure messages
- getMessageTemplates() : array<string, string>
- Returns the message templates from the validator
- getMessageVariables() : array<int, string>
- Returns an array of the names of variables that are used in constructing validation failure messages
- getOption() : mixed
- Returns an option
- getOptions() : array<string, mixed>
- Returns all available options
- getTranslator() : TranslatorInterface|null
- Return translation object
- getTranslatorTextDomain() : string
- Return the translation text domain
- hasDefaultTranslator() : bool
- Is there a default translation object set?
- hasTranslator() : bool
- Does this validator have its own specific translator?
- isTranslatorEnabled() : bool
- Is translation enabled?
- isValid() : bool
- Returns true if and only if $value meets the validation requirements
- isValueObscured() : bool
- Retrieve flag indicating whether or not value should be obfuscated in messages
- setAllow() : void
- setDefaultTranslator() : void
- Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() : void
- Set default translation text domain for all validate objects
- setMaxDepth() : void
- setMessage() : $this
- Sets the validation failure message template for a particular key
- setMessageLength() : void
- Sets the maximum allowed message length
- setMessages() : $this
- Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
- setOptions() : $this
- Sets one or multiple options
- setTranslator() : $this
- Set translation object
- setTranslatorEnabled() : $this
- Indicate whether or not translation should be enabled
- setTranslatorTextDomain() : $this
- Set translation text domain
- setValueObscured() : $this
- Set flag indicating whether or not value should be obfuscated in messages
- createMessage() : null|string
- Constructs and returns a validation failure message with the given message key and value.
- error() : void
- getValue() : mixed
- Returns the validation value
- setValue() : void
- Sets the value to be validated and clears the messages and errors arrays
- translateMessage() : string
- Translate a validation message
- isAllowed() : bool
Constants
ALLOW_ALL
public
mixed
ALLOW_ALL
= 0b11111
ALLOW_ARRAY
public
mixed
ALLOW_ARRAY
= 0b1000
ALLOW_BOOL
public
mixed
ALLOW_BOOL
= 0b100
ALLOW_FLOAT
public
mixed
ALLOW_FLOAT
= 0b10
ALLOW_INT
public
mixed
ALLOW_INT
= 0b1
ALLOW_OBJECT
public
mixed
ALLOW_OBJECT
= 0b10000
ERROR_INVALID_JSON
public
mixed
ERROR_INVALID_JSON
= 'errorInvalidJson'
ERROR_MAX_DEPTH_EXCEEDED
public
mixed
ERROR_MAX_DEPTH_EXCEEDED
= 'errorMaxDepthExceeded'
ERROR_NOT_STRING
public
mixed
ERROR_NOT_STRING
= 'errorNotString'
ERROR_TYPE_NOT_ALLOWED
public
mixed
ERROR_TYPE_NOT_ALLOWED
= 'errorTypeNotAllowed'
Properties
$messageTemplates
public
array<string, string>
$messageTemplates
$messageVariables
public
array<string, mixed>
$messageVariables
$options
public
array<string, mixed>
$options
$abstractOptions
protected
AbstractOptions|array<string, mixed>
$abstractOptions
= [
'messages' => [],
// Array of validation failure messages
'messageTemplates' => [],
// Array of validation failure message templates
'messageVariables' => [],
// Array of additional variables available for validation failure messages
'translator' => null,
// Translation object to used -> Translator\TranslatorInterface
'translatorTextDomain' => null,
// Translation text domain
'translatorEnabled' => true,
// Is translation enabled?
'valueObscured' => false,
]
$allow
protected
int
$allow
= self::ALLOW_ALL
int-mask-ofself::ALLOW_*
$defaultTranslator
Default translation object for all validate objects
protected
static TranslatorInterface
$defaultTranslator
$defaultTranslatorTextDomain
Default text domain to be used with translator
protected
static string
$defaultTranslatorTextDomain
= 'default'
$maxDepth
protected
positive-int
$maxDepth
= 512
$messageLength
Limits the maximum returned length of an error message
protected
static int
$messageLength
= -1
$messageTemplates
protected
mixed
$messageTemplates
= [self::ERROR_NOT_STRING => 'Expected a string but %type% was received', self::ERROR_TYPE_NOT_ALLOWED => 'Received a JSON %type% but this type is not acceptable', self::ERROR_MAX_DEPTH_EXCEEDED => 'The decoded JSON payload exceeds the allowed depth of %maxDepth%', self::ERROR_INVALID_JSON => 'An invalid JSON payload was received']
$messageVariables
protected
array<string, string>
$messageVariables
= ['type' => 'type', 'maxDepth' => 'maxDepth']
$type
protected
string|null
$type
= null
$value
The value to be validated
protected
mixed
$value
Methods
__construct()
Abstract constructor for all validators A validator should accept following parameters: - nothing f.e. Validator() - one or multiple scalar values f.e. Validator($first, $second, $third) - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third')) - an instance of Traversable f.e. Validator($config_instance)
public
__construct([array<string, mixed>|Traversable<string, mixed> $options = null ]) : mixed
Parameters
- $options : array<string, mixed>|Traversable<string, mixed> = null
__get()
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__invoke()
Invoke as command
public
__invoke(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolgetDefaultTranslator()
Get default translation object for all validate objects
public
static getDefaultTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetDefaultTranslatorTextDomain()
Get default translation text domain for all validate objects
public
static getDefaultTranslatorTextDomain() : string
Return values
stringgetMessageLength()
Returns the maximum allowed message length
public
static getMessageLength() : int
Return values
intgetMessages()
Returns array of validation failure messages
public
getMessages() : array<string, string>
Return values
array<string, string>getMessageTemplates()
Returns the message templates from the validator
public
getMessageTemplates() : array<string, string>
Return values
array<string, string>getMessageVariables()
Returns an array of the names of variables that are used in constructing validation failure messages
public
getMessageVariables() : array<int, string>
Return values
array<int, string>getOption()
Returns an option
public
getOption(string $option) : mixed
Parameters
- $option : string
-
Option to be returned
Tags
Return values
mixed —Returned option
getOptions()
Returns all available options
public
getOptions() : array<string, mixed>
Return values
array<string, mixed> —Array with all available options
getTranslator()
Return translation object
public
getTranslator() : TranslatorInterface|null
Return values
TranslatorInterface|nullgetTranslatorTextDomain()
Return the translation text domain
public
getTranslatorTextDomain() : string
Return values
stringhasDefaultTranslator()
Is there a default translation object set?
public
static hasDefaultTranslator() : bool
Return values
boolhasTranslator()
Does this validator have its own specific translator?
public
hasTranslator() : bool
Return values
boolisTranslatorEnabled()
Is translation enabled?
public
isTranslatorEnabled() : bool
Return values
boolisValid()
Returns true if and only if $value meets the validation requirements
public
isValid(mixed $value) : bool
If $value fails validation, then this method returns false, and getMessages() will return an array of messages that explain why the validation failed.
Parameters
- $value : mixed
Return values
boolisValueObscured()
Retrieve flag indicating whether or not value should be obfuscated in messages
public
isValueObscured() : bool
Return values
boolsetAllow()
public
setAllow(int $type) : void
Parameters
- $type : int
setDefaultTranslator()
Set default translation object for all validate objects
public
static setDefaultTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : void
Parameters
- $translator : TranslatorInterface|null = null
- $textDomain : string = null
-
(optional)
Tags
setDefaultTranslatorTextDomain()
Set default translation text domain for all validate objects
public
static setDefaultTranslatorTextDomain([string $textDomain = 'default' ]) : void
Parameters
- $textDomain : string = 'default'
setMaxDepth()
public
setMaxDepth(positive-int $maxDepth) : void
Parameters
- $maxDepth : positive-int
setMessage()
Sets the validation failure message template for a particular key
public
setMessage(string $messageString[, string|null $messageKey = null ]) : $this
Parameters
- $messageString : string
- $messageKey : string|null = null
-
OPTIONAL
Tags
Return values
$this —Provides a fluent interface
setMessageLength()
Sets the maximum allowed message length
public
static setMessageLength([int $length = -1 ]) : void
Parameters
- $length : int = -1
setMessages()
Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
public
setMessages(array<string, string> $messages) : $this
Parameters
- $messages : array<string, string>
Return values
$thissetOptions()
Sets one or multiple options
public
setOptions([array<string, mixed>|Traversable<string, mixed> $options = [] ]) : $this
Parameters
- $options : array<string, mixed>|Traversable<string, mixed> = []
-
Options to set
Tags
Return values
$this —Provides fluid interface
setTranslator()
Set translation object
public
setTranslator([TranslatorInterface|null $translator = null ][, string $textDomain = null ]) : $this
Parameters
- $translator : TranslatorInterface|null = null
-
[optional] translator. Default is null, which sets no translator.
- $textDomain : string = null
-
(optional)
Tags
Return values
$thissetTranslatorEnabled()
Indicate whether or not translation should be enabled
public
setTranslatorEnabled([bool $enabled = true ]) : $this
Parameters
- $enabled : bool = true
Return values
$thissetTranslatorTextDomain()
Set translation text domain
public
setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
- $textDomain : string = 'default'
Return values
$thissetValueObscured()
Set flag indicating whether or not value should be obfuscated in messages
public
setValueObscured(bool $flag) : $this
Parameters
- $flag : bool
Return values
$thiscreateMessage()
Constructs and returns a validation failure message with the given message key and value.
protected
createMessage(string $messageKey, string|array<string|int, mixed>|object $value) : null|string
Returns null if and only if $messageKey does not correspond to an existing template.
If a translator is available and a translation exists for $messageKey, the translation will be used.
Parameters
- $messageKey : string
- $value : string|array<string|int, mixed>|object
Return values
null|stringerror()
protected
error(string|null $messageKey[, null|string|array<string|int, mixed>|object $value = null ]) : void
Parameters
- $messageKey : string|null
- $value : null|string|array<string|int, mixed>|object = null
-
OPTIONAL
getValue()
Returns the validation value
protected
getValue() : mixed
Return values
mixed —Value to be validated
setValue()
Sets the value to be validated and clears the messages and errors arrays
protected
setValue(mixed $value) : void
Parameters
- $value : mixed
translateMessage()
Translate a validation message
protected
translateMessage(string $messageKey, string $message) : string
Parameters
- $messageKey : string
- $message : string
Return values
stringisAllowed()
private
isAllowed(self::ALLOW_* $flag) : bool
Parameters
- $flag : self::ALLOW_*