Contains
extends AbstractValidator
in package
uses
ValueComparisonTrait
Contains validator class
Tags
Table of Contents
Properties
- $description : string|null
- Validator description
- $field : string|null
- Input field
- $input : mixed
- Input value to test
- $message : string|null
- Validator message - The message provided when the validation fails
- $name : string|null
- Validator name
- $results : mixed
- Validator results - Optional results to collect post-validation, would be something that was set by a custom validator in its "evaluate" method
- $value : mixed
- Validator value to test against
Methods
- __construct() : mixed
- Constructor
- evaluate() : bool
- Method to evaluate the validator
- generateDefaultMessage() : string
- Generate default message
- getDescription() : string|null
- Get the validator description
- getField() : string|array<string|int, mixed>|null
- Get the validator field
- getInput() : mixed
- Get the validator input
- getKeyFieldValue() : mixed
- Get the validator key field value
- getMessage() : string|null
- Get the validator default message
- getName() : string|null
- Get the validator name
- getResults() : mixed
- Get the validator results
- getValue() : mixed
- Get the validator value
- hasDescription() : bool
- Has validator description
- hasField() : bool
- Has validator field
- hasInput() : bool
- Has validator input
- hasKeyField() : bool
- Has validator key field
- hasMessage() : bool
- Has validator message
- hasName() : bool
- Has validator name
- hasResults() : bool
- Has validator results
- hasValue() : bool
- Has validator value
- setDescription() : static
- Set the validator description
- setField() : AbstractValidator
- Set the validator field
- setInput() : AbstractValidator
- Set the validator input
- setMessage() : AbstractValidator
- Set the validator condition
- setName() : static
- Set the validator name
- setValue() : static
- Set the validator value
- containsMatch() : bool
- Determine if $needle is contained within $haystack (used by Contains/NotContains)
- containsNoneMatch() : bool
- Determine if none of $needle is contained within $haystack (used by NotContains)
- endsWithMatch() : bool
- Determine if $inputValue ends with $comparisonValue (used by EndsWith/NotEndsWith)
- inMatch() : bool
- Determine if $needle is contained within $haystack (used by In/NotIn)
- inNoneMatch() : bool
- Determine if none of $needle is contained within $haystack (used by NotIn)
- resolveComparisonValueString() : string
- Resolve the comparison value string used in default messages (used by StartsWith/NotStartsWith/EndsWith/NotEndsWith)
- resolveInputValue() : mixed
- Resolve the input value, honoring bracket key-field notation
- startsWithMatch() : bool
- Determine if $inputValue starts with $comparisonValue (used by StartsWith/NotStartsWith)
Properties
$description
Validator description
protected
string|null
$description
= null
$field
Input field
protected
string|null
$field
= null
$input
Input value to test
protected
mixed
$input
= null
$message
Validator message - The message provided when the validation fails
protected
string|null
$message
= null
$name
Validator name
protected
string|null
$name
= null
$results
Validator results - Optional results to collect post-validation, would be something that was set by a custom validator in its "evaluate" method
protected
mixed
$results
= null
$value
Validator value to test against
protected
mixed
$value
= null
Methods
__construct()
Constructor
public
__construct([mixed $value = null ][, string|null $message = null ][, string|null $name = null ][, string|null $description = null ]) : mixed
Instantiate the validator object
Parameters
- $value : mixed = null
- $message : string|null = null
- $name : string|null = null
- $description : string|null = null
evaluate()
Method to evaluate the validator
public
evaluate([mixed $input = null ]) : bool
Parameters
- $input : mixed = null
Return values
boolgenerateDefaultMessage()
Generate default message
public
generateDefaultMessage([mixed $name = null ][, mixed $value = null ]) : string
Parameters
- $name : mixed = null
- $value : mixed = null
Return values
stringgetDescription()
Get the validator description
public
getDescription() : string|null
Return values
string|nullgetField()
Get the validator field
public
getField([bool $parse = true ]) : string|array<string|int, mixed>|null
Parameters
- $parse : bool = true
Return values
string|array<string|int, mixed>|nullgetInput()
Get the validator input
public
getInput() : mixed
getKeyFieldValue()
Get the validator key field value
public
getKeyFieldValue() : mixed
getMessage()
Get the validator default message
public
getMessage() : string|null
Return values
string|nullgetName()
Get the validator name
public
getName() : string|null
Return values
string|nullgetResults()
Get the validator results
public
getResults() : mixed
getValue()
Get the validator value
public
getValue() : mixed
hasDescription()
Has validator description
public
hasDescription() : bool
Return values
boolhasField()
Has validator field
public
hasField() : bool
Return values
boolhasInput()
Has validator input
public
hasInput() : bool
Return values
boolhasKeyField()
Has validator key field
public
hasKeyField() : bool
Return values
boolhasMessage()
Has validator message
public
hasMessage() : bool
Return values
boolhasName()
Has validator name
public
hasName() : bool
Return values
boolhasResults()
Has validator results
public
hasResults() : bool
Return values
boolhasValue()
Has validator value
public
hasValue() : bool
Return values
boolsetDescription()
Set the validator description
public
setDescription([string|null $description = null ]) : static
Parameters
- $description : string|null = null
Return values
staticsetField()
Set the validator field
public
setField([string|null $field = null ]) : AbstractValidator
Parameters
- $field : string|null = null
Return values
AbstractValidatorsetInput()
Set the validator input
public
setInput([mixed $input = null ]) : AbstractValidator
Parameters
- $input : mixed = null
Return values
AbstractValidatorsetMessage()
Set the validator condition
public
setMessage([string|null $message = null ]) : AbstractValidator
Parameters
- $message : string|null = null
Return values
AbstractValidatorsetName()
Set the validator name
public
setName([string|null $name = null ]) : static
Parameters
- $name : string|null = null
Return values
staticsetValue()
Set the validator value
public
setValue(mixed $value) : static
Parameters
- $value : mixed
Return values
staticcontainsMatch()
Determine if $needle is contained within $haystack (used by Contains/NotContains)
protected
containsMatch(mixed $needle, mixed $haystack) : bool
Parameters
- $needle : mixed
- $haystack : mixed
Return values
boolcontainsNoneMatch()
Determine if none of $needle is contained within $haystack (used by NotContains)
protected
containsNoneMatch(mixed $needle, mixed $haystack) : bool
Note: not a simple boolean negation of containsMatch() — when $needle is an array compared against a scalar $haystack, this requires that none of $needle's elements are found (NOR), whereas containsMatch() requires that all of them are found (AND).
Parameters
- $needle : mixed
- $haystack : mixed
Return values
boolendsWithMatch()
Determine if $inputValue ends with $comparisonValue (used by EndsWith/NotEndsWith)
protected
endsWithMatch(mixed $inputValue, mixed $comparisonValue) : bool
An array $inputValue is never considered to "end with" anything, guarding against PHP silently coercing the array to the literal string "Array" and matching on that.
Parameters
- $inputValue : mixed
- $comparisonValue : mixed
Return values
boolinMatch()
Determine if $needle is contained within $haystack (used by In/NotIn)
protected
inMatch(mixed $needle, mixed $haystack) : bool
Parameters
- $needle : mixed
- $haystack : mixed
Return values
boolinNoneMatch()
Determine if none of $needle is contained within $haystack (used by NotIn)
protected
inNoneMatch(mixed $needle, mixed $haystack) : bool
Note: not a simple boolean negation of inMatch() — when $needle is an array compared against a scalar $haystack, this requires that none of $needle's elements are found (NOR), whereas inMatch() requires that all of them are found (AND).
Parameters
- $needle : mixed
- $haystack : mixed
Return values
boolresolveComparisonValueString()
Resolve the comparison value string used in default messages (used by StartsWith/NotStartsWith/EndsWith/NotEndsWith)
protected
resolveComparisonValueString(mixed $value) : string
Parameters
- $value : mixed
Return values
stringresolveInputValue()
Resolve the input value, honoring bracket key-field notation
protected
resolveInputValue() : mixed
startsWithMatch()
Determine if $inputValue starts with $comparisonValue (used by StartsWith/NotStartsWith)
protected
startsWithMatch(mixed $inputValue, mixed $comparisonValue) : bool
An array $inputValue is never considered to "start with" anything, guarding against PHP silently coercing the array to the literal string "Array" and matching on that.
Parameters
- $inputValue : mixed
- $comparisonValue : mixed