NoRecordExists
extends AbstractDb
in package
Confirms a record does not exist in a table.
Table of Contents
Constants
- ERROR_NO_RECORD_FOUND = 'noRecordFound'
- Error constants
- ERROR_RECORD_FOUND = 'recordFound'
Properties
- $messageTemplates : array<string, string>
- $messageVariables : array<string, mixed>
- $options : array<string, mixed>
- $abstractOptions : AbstractOptions|array<string, mixed>
- $defaultTranslator : TranslatorInterface
- Default translation object for all validate objects
- $defaultTranslatorTextDomain : string
- Default text domain to be used with translator
- $exclude : mixed
- $field : string
- $messageLength : int
- Limits the maximum returned length of an error message
- $messageTemplates : array<string, string>
- $schema : string
- $select : Select
- Select object to use. can be set, or will be auto-generated
- $table : string
- $value : mixed
- The value to be validated
Methods
- __construct() : mixed
- Provides basic configuration for use with Laminas\Validator\Db Validators Setting $exclude allows a single record to be excluded from matching.
- __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
- getAdapter() : Adapter
- Returns the set adapter
- getDefaultTranslator() : TranslatorInterface|null
- Get default translation object for all validate objects
- getDefaultTranslatorTextDomain() : string
- Get default translation text domain for all validate objects
- getExclude() : string|array<string|int, mixed>
- Returns the set exclude clause
- getField() : string|array<string|int, mixed>
- Returns the set field
- 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
- getSchema() : string
- Returns the set schema
- getSelect() : Select
- Gets the select object to be used by the validator.
- getTable() : string
- Returns the set table
- 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
- setAdapter() : self
- Sets a new database adapter
- setDefaultTranslator() : void
- Set default translation object for all validate objects
- setDefaultTranslatorTextDomain() : void
- Set default translation text domain for all validate objects
- setExclude() : $this
- Sets a new exclude clause
- setField() : $this
- Sets a new field
- 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
- setSchema() : $this
- Sets a new schema
- setSelect() : $this
- Sets the select object to be used by the validator
- setTable() : $this
- Sets a new table
- 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
- query() : array<string|int, mixed>
- Run query and returns matches, or null if no matches are found.
- setValue() : void
- Sets the value to be validated and clears the messages and errors arrays
- translateMessage() : string
- Translate a validation message
Constants
ERROR_NO_RECORD_FOUND
Error constants
public
mixed
ERROR_NO_RECORD_FOUND
= 'noRecordFound'
ERROR_RECORD_FOUND
public
mixed
ERROR_RECORD_FOUND
= 'recordFound'
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,
]
$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'
$exclude
protected
mixed
$exclude
$field
protected
string
$field
= ''
$messageLength
Limits the maximum returned length of an error message
protected
static int
$messageLength
= -1
$messageTemplates
protected
array<string, string>
$messageTemplates
= [self::ERROR_NO_RECORD_FOUND => 'No record matching the input was found', self::ERROR_RECORD_FOUND => 'A record matching the input was found']
Message templates
$schema
protected
string
$schema
$select
Select object to use. can be set, or will be auto-generated
protected
Select
$select
$table
protected
string
$table
= ''
$value
The value to be validated
protected
mixed
$value
Methods
__construct()
Provides basic configuration for use with Laminas\Validator\Db Validators Setting $exclude allows a single record to be excluded from matching.
public
__construct([array<string|int, mixed>|Traversable|Select $options = null ]) : mixed
Exclude can either be a String containing a where clause, or an array with field
and value
keys
to define the where clause added to the sql.
A database adapter may optionally be supplied to avoid using the registered default adapter.
The following option keys are supported: 'table' => The database table to validate against 'schema' => The schema keys 'field' => The field to check for a match 'exclude' => An optional where clause or field/value pair to exclude from the query 'adapter' => An optional database adapter to use
Parameters
- $options : array<string|int, mixed>|Traversable|Select = null
-
Options to use for this validator
Tags
__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
boolgetAdapter()
Returns the set adapter
public
getAdapter() : Adapter
Tags
Return values
AdaptergetDefaultTranslator()
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
stringgetExclude()
Returns the set exclude clause
public
getExclude() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed>getField()
Returns the set field
public
getField() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed>getMessageLength()
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
getSchema()
Returns the set schema
public
getSchema() : string
Return values
stringgetSelect()
Gets the select object to be used by the validator.
public
getSelect() : Select
If no select object was supplied to the constructor, then it will auto-generate one from the given table, schema, field, and adapter options.
Return values
Select —The Select object which will be used
getTable()
Returns the set table
public
getTable() : string
Return values
stringgetTranslator()
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
Parameters
- $value : mixed
Return values
boolisValueObscured()
Retrieve flag indicating whether or not value should be obfuscated in messages
public
isValueObscured() : bool
Return values
boolsetAdapter()
Sets a new database adapter
public
setAdapter(Adapter $adapter) : self
Parameters
- $adapter : Adapter
Return values
self —Provides a fluent interface
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'
setExclude()
Sets a new exclude clause
public
setExclude(string|array<string|int, mixed> $exclude) : $this
Parameters
- $exclude : string|array<string|int, mixed>
Return values
$this —Provides a fluent interface
setField()
Sets a new field
public
setField(string $field) : $this
Parameters
- $field : string
Return values
$thissetMessage()
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
setSchema()
Sets a new schema
public
setSchema(string $schema) : $this
Parameters
- $schema : string
Return values
$this —Provides a fluent interface
setSelect()
Sets the select object to be used by the validator
public
setSelect(Select $select) : $this
Parameters
- $select : Select
Return values
$this —Provides a fluent interface
setTable()
Sets a new table
public
setTable(string $table) : $this
Parameters
- $table : string
Return values
$this —Provides a fluent 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
query()
Run query and returns matches, or null if no matches are found.
protected
query(string $value) : array<string|int, mixed>
Parameters
- $value : string
Return values
array<string|int, mixed> —when matches are found.
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