Class craft\validators\ArrayValidator
- Inheritance
- craft\validators\ArrayValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/validators/ArrayValidator.php
Class ArrayValidator.
Property | Type | Description | Defined By |
---|---|---|---|
$attributes |
array, string | Attributes to be validated by this validator. | yii\validators\Validator |
$builtInValidators |
array | List of built-in validators (name => class or configuration) | yii\validators\Validator |
$count |
integer, array, null | Specifies the count limit of the value to be validated. | craft\validators\ArrayValidator |
$enableClientValidation |
boolean | Whether to enable client-side validation for this validator. | yii\validators\Validator |
$except |
array, string | Scenarios that the validator should not be applied to. | yii\validators\Validator |
$isEmpty |
callable | A PHP callable that replaces the default implementation of isEmpty(). | yii\validators\Validator |
$max |
integer, null | Maximum count. | craft\validators\ArrayValidator |
$message |
string | The user-defined error message. | yii\validators\Validator |
$min |
integer, null | Minimum count. | craft\validators\ArrayValidator |
$notEqual |
string, null | User-defined error message used when the count of the value is not equal to $count. | craft\validators\ArrayValidator |
$on |
array, string | Scenarios that the validator can be applied to. | yii\validators\Validator |
$skipOnEmpty |
boolean | Whether this validation rule should be skipped if the attribute value is null or an empty string. | yii\validators\Validator |
$skipOnError |
boolean | Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules. | yii\validators\Validator |
$tooFew |
string, null | User-defined error message used when the count of the value is smaller than $min. | craft\validators\ArrayValidator |
$tooMany |
string, null | User-defined error message used when the count of the value is greater than $max. | craft\validators\ArrayValidator |
$when |
callable | A PHP callable whose return value determines whether this validator should be applied. | yii\validators\Validator |
$whenClient |
string | A JavaScript function name whose return value determines whether this validator should be applied on the client-side. | yii\validators\Validator |
Method | Description | Defined By |
---|---|---|
__call() |
Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() |
This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() |
Constructor. | yii\base\BaseObject |
__get() |
Returns the value of an object property. | yii\base\BaseObject |
__isset() |
Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() |
Sets value of an object property. | yii\base\BaseObject |
__unset() |
Sets an object property to null. | yii\base\BaseObject |
addError() |
Adds an error about the specified attribute to the model object. | yii\validators\Validator |
attachBehavior() |
Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() |
Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() |
Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() |
Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() |
Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() |
Returns the fully qualified name of this class. | yii\base\BaseObject |
clientValidateAttribute() |
Returns the JavaScript needed for performing client-side validation. | yii\validators\Validator |
createValidator() |
Creates a validator object. | yii\validators\Validator |
detachBehavior() |
Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() |
Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() |
Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getAttributeNames() |
Returns cleaned attribute names without the ! character at the beginning. |
yii\validators\Validator |
getBehavior() |
Returns the named behavior object. | yii\base\Component |
getBehaviors() |
Returns all behaviors attached to this component. | yii\base\Component |
getClientOptions() |
Returns the client-side validation options. | yii\validators\Validator |
hasEventHandlers() |
Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() |
Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() |
Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() |
{@inheritdoc} | craft\validators\ArrayValidator |
isActive() |
Returns a value indicating whether the validator is active for the given scenario and attribute. | yii\validators\Validator |
isEmpty() |
Checks if the given value is empty. | yii\validators\Validator |
off() |
Detaches an existing event handler from this component. | yii\base\Component |
on() |
Attaches an event handler to an event. | yii\base\Component |
trigger() |
Triggers an event. | yii\base\Component |
validate() |
Validates a given value. | yii\validators\Validator |
validateAttribute() |
Validates a single attribute. | craft\validators\ArrayValidator |
validateAttributes() |
Validates the specified object. | yii\validators\Validator |
Method | Description | Defined By |
---|---|---|
formatMessage() |
Formats a mesage using the I18N, or simple strtr if \Yii::$app is not available. |
yii\validators\Validator |
validateValue() |
Validates a value. | craft\validators\ArrayValidator |
Property Details
$count
public property
#
Specifies the count limit of the value to be validated. This can be specified in one of the following forms:
- an int: the exact count that the value should be of;
- an array of one element: the minimum count that the value should be of. For example,
[8]
. This will overwrite $min. - an array of two elements: the minimum and maximum counts that the value should be of.
For example,
[8, 128]
. This will overwrite both $min and $max.
See also:
- $tooFew for the customized message for a too short array.
- $tooMany for the customized message for a too long array.
- $notEqual for the customized message for an array that does not match desired count.
public integer, array, null $count = null
$max
public property
#
Maximum count. If not set, it means no maximum count limit.
See also $tooMany for the customized message for a too long array.
public integer, null $max = null
$min
public property
#
Minimum count. If not set, it means no minimum count limit.
See also $tooFew for the customized message for a too short array.
public integer, null $min = null
$notEqual
public property
#
User-defined error message used when the count of the value is not equal to $count.
public string, null $notEqual = null
$tooFew
public property
#
User-defined error message used when the count of the value is smaller than $min.
public string, null $tooFew = null
$tooMany
public property
#
User-defined error message used when the count of the value is greater than $max.
public string, null $tooMany = null
Method Details
init()
public method
#
{@inheritdoc}
public void init ( )
validateAttribute()
public method
#
Validates a single attribute.
Child classes must implement this method to provide the actual validation logic.
public void validateAttribute ( $model, $attribute )
$model |
yii\base\Model | The data model to be validated |
$attribute |
string | The name of the attribute to be validated. |
validateValue()
protected method
#
Validates a value.
A validator class can implement this method to support data validation out of the context of a data model.
protected array, null validateValue ( $value )
$value |
mixed | The data value to be validated. |
return | array, null | The error message and the array of parameters to be inserted into the error message.
` php
if (!$valid) {
return [$this->message, [
'param1' => $this->param1,
'formattedLimit' => Yii::$app->formatter->asShortSize($this->getSizeLimit()),
'mimeTypes' => implode(', ', $this->mimeTypes),
'param4' => 'etc...',
]];
}
return null;
`
for this example message template can contain {param1} , {formattedLimit} , {mimeTypes} , {param4}
Null should be returned if the data is valid.
|
---|---|---|
throws | yii\base\NotSupportedException | if the validator does not supporting data validation without a model |