for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Validator\Rule;
use Yiisoft\Validator\DataSetInterface;
use Yiisoft\Validator\HasValidationErrorMessage;
use Yiisoft\Validator\Result;
use Yiisoft\Validator\Rule;
/**
* RequiredValidator validates that the specified attribute does not have null or empty value.
*/
class Required extends Rule
{
use HasValidationErrorMessage;
private string $message = 'Value cannot be blank.';
protected function validateValue($value, DataSetInterface $dataSet = null): Result
$result = new Result();
if ($this->isEmpty(is_string($value) ? trim($value) : $value)) {
$result->addError($this->translateMessage($this->message));
}
return $result;
public function getOptions(): array
return array_merge(
parent::getOptions(),
[
'message' => $this->translateMessage($this->message),
],
);