NoraLib Validation API Documentation

AnyOfRule extends AbstractRule
in package

いずれか1つ以上のルールが成功することを要求します(論理OR)

複数のルールのうち、少なくとも1つが成功すればバリデーション成功となります。

OpenAPI 3.0の anyOf に対応します。

Tags
example
$validator = new Validator();
// メールアドレスまたはURL形式
$rule = $validator->anyOf([
    $validator->validEmail(),
    $validator->validUrl()
]);
$rule->assert('user@example.com'); // OK (email成功)
$rule->assert('https://example.com'); // OK (URL成功)
$rule->assert('invalid'); // Exception (両方失敗)

Table of Contents

Properties

$message  : string
$rules  : array<string|int, mixed>

Methods

__construct()  : mixed
assert()  : void
validate()  : bool
raiseError()  : RuleExceptionInterface

Properties

$message

protected string $message = 'いずれかのルールを満たす必要があります。'

$rules

private array<string|int, mixed> $rules

Methods

__construct()

public __construct(array<string|int, ValidatorInterface$rules[, string $message = 'いずれかのルールを満たす必要があります。' ]) : mixed
Parameters
$rules : array<string|int, ValidatorInterface>
$message : string = 'いずれかのルールを満たす必要があります。'

assert()

public assert(mixed $value) : void
Parameters
$value : mixed

validate()

public validate(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

        
On this page

Search results