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\Subset;
use Attribute;
use Closure;
use Yiisoft\Validator\Rule\RuleNameTrait;
use Yiisoft\Validator\Rule\HandlerClassNameTrait;
use Yiisoft\Validator\RuleInterface;
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Subset implements RuleInterface
{
use HandlerClassNameTrait;
use RuleNameTrait;
public function __construct(
public iterable $values,
/**
* @var bool whether the comparison is strict (both type and value must be the same)
*/
public bool $strict = false,
public string $iterableMessage = 'Value must be iterable.',
public string $subsetMessage = 'Values must be ones of {values}.',
public bool $skipOnEmpty = false,
public bool $skipOnError = false,
public ?Closure $when = null,
) {
}
public function getOptions(): array
return [
'values' => $this->values,
'strict' => $this->strict,
'iterableMessage' => [
'message' => $this->iterableMessage,
],
'subsetMessage' => [
'message' => $this->subsetMessage,
'skipOnEmpty' => $this->skipOnEmpty,
'skipOnError' => $this->skipOnError,
];