|
|
@@ -2349,8 +2349,30 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
|
|
|
* @see \Cake\Validation\Validation::isArray()
|
|
|
* @return $this
|
|
|
*/
|
|
|
+ public function array(string $field, ?string $message = null, $when = null)
|
|
|
+ {
|
|
|
+ $extra = array_filter(['on' => $when, 'message' => $message]);
|
|
|
+
|
|
|
+ return $this->add($field, 'array', $extra + [
|
|
|
+ 'rule' => 'isArray',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add a validation rule to ensure that a field contains an array.
|
|
|
+ *
|
|
|
+ * @param string $field The field you want to apply the rule to.
|
|
|
+ * @param string|null $message The error message when the rule fails.
|
|
|
+ * @param callable|string|null $when Either 'create' or 'update' or a callable that returns
|
|
|
+ * true when the validation rule should be applied.
|
|
|
+ * @see \Cake\Validation\Validation::isArray()
|
|
|
+ * @return $this
|
|
|
+ * @deprecated 4.5.0 Use Validator::array() instead.
|
|
|
+ */
|
|
|
public function isArray(string $field, ?string $message = null, $when = null)
|
|
|
{
|
|
|
+ deprecationWarning('`Validator::isArray()` is deprecated, use `Validator::array()` instead');
|
|
|
+
|
|
|
$extra = array_filter(['on' => $when, 'message' => $message]);
|
|
|
|
|
|
return $this->add($field, 'isArray', $extra + [
|