public function __construct(Comfort $comfort) { parent::__construct($comfort); $this->toBool(false); $this->add(function ($value, $nameKey) { json_decode($value); if (json_last_error() != JSON_ERROR_NONE) { return $this->createError('json.invalid', $value, $nameKey); } }); }
/** * ArrayValidator constructor. * @param Comfort $comfort */ public function __construct(Comfort $comfort) { parent::__construct($comfort); $this->toBool(false); $this->add(function ($value, $nameKey) { if (!is_array($value)) { return $this->createError('array.not_array', $value, $nameKey); } }); $this->errorHandlers += ['array.min' => ['message' => '%s must contains at least %s elements'], 'array.max' => ['message' => '%s must contain no more than %s elements'], 'array.length' => ['message' => '%s must only contain %s elements'], 'array.unique' => ['message' => '%s is not an array containing all unique values'], 'array.items.validation_failure' => ['message' => '%s has an item that fails validation'], 'array.not_array' => ['message' => '%s is not an array']]; }
public function __construct(Comfort $comfort) { parent::__construct($comfort); $this->errorHandlers += ['string.length' => ['message' => '%s does not match exactly length'], 'string.alpha' => ['message' => '%s is not alpha numeric'], 'string.token' => ['message' => '%s is not a token'], 'string.min' => ['message' => '%s must be more than % characters long'], 'string.max' => ['message' => '%s must be less than % characters long'], 'string.alphanum' => ['message' => '%s must be alphanumeric'], 'string.matches' => ['message' => '%s does not match %s'], 'string.email' => ['message' => '%s must be an email'], 'string.ip' => ['message' => '%s must be an IP'], 'string.uri' => ['message' => '%s must be a URI']]; $this->add(function ($value, $nameKey) { if (is_null($value)) { return; } if (!is_string($value)) { $this->createError('string.type', $value, $nameKey); } }); }
public function __construct(Comfort $comfort) { parent::__construct($comfort); $this->errorHandlers += ['number.min' => ['message' => '%s must be above %s'], 'number.max' => ['message' => '%s must be below %s'], 'number.precision' => ['message' => '%s must be precision %s'], 'number.is_int' => ['message' => '%s must be an int'], 'number.is_float' => ['message' => '%s must be a float'], 'number.is_number' => ['message' => '%s must be a number'], 'number.negative' => ['message' => '%s must be negative'], 'number.positive' => ['message' => '%s must be positive']]; $this->isNumber(); }