1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<?php
namespace ICanBoogie\Validate\Validator;
use ICanBoogie\Validate\Context;
class Required extends AbstractValidator
{
const ALIAS = 'required';
const DEFAULT_MESSAGE = "is required";
public function normalize_params(array $params)
{
return array_merge([
self::OPTION_STOP_ON_ERROR => true
], parent::normalize_params($params));
}
public function validate($value, Context $context)
{
return $value !== null || (is_array($value) && count($value)) || (is_scalar($value) && trim($value) !== '');
}
}